dcarbone / gohttp
Golang-like http class(es) for PHP 8.2+
v1.0.1
2026-07-02 22:42 UTC
Requires
- php: ^8.2
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^11.5
This package is auto-updated.
Last update: 2026-07-02 22:43:52 UTC
README
Golang-inspired HTTP helpers for PHP, including:
- HTTP status code constants
- HTTP method constants
- status text / status name helpers
- a small
URL\Valuescontainer for query-style key/value lists
Requirements
- PHP 8.2+
ext-json
Installation
composer require dcarbone/gohttp
Usage
Status helpers
<?php declare(strict_types=1); use DCarbone\Go\HTTP\HTTP; echo HTTP::StatusOK; // 200 echo HTTP::StatusText(HTTP::StatusNotFound); // "Not Found" echo HTTP::StatusName(HTTP::StatusNotFound); // "NotFound"
Namespace functions
The package also provides namespaced functions:
<?php declare(strict_types=1); use function DCarbone\Go\HTTP\StatusName; use function DCarbone\Go\HTTP\StatusText; echo StatusText(418); // "I'm a teapot" echo StatusName(418); // "Teapot"
Methods
<?php declare(strict_types=1); use DCarbone\Go\HTTP\HTTP; $methods = [ HTTP::MethodGet, HTTP::MethodPost, HTTP::MethodPut, HTTP::MethodPatch, HTTP::MethodDelete, ];
URL values
<?php declare(strict_types=1); use DCarbone\Go\HTTP\URL\Values; $values = new Values(); $values->add('filter', 'active'); $values->add('filter', 'recent'); $values->set('page', '1'); echo $values->get('filter'); // "active" print_r($values->getAll('filter')); // ["active", "recent"] echo (string)$values; // "filter=active&filter=recent&page=1"
Values implements Iterator, ArrayAccess, Countable, and JsonSerializable.
Development
Install dependencies:
composer install
Run unit tests:
composer test
License
MIT