dcarbone/gohttp
Small PHP helper library inspired by Go’s net/http. Provides lightweight, Go-style utilities to simplify common HTTP request/response tasks in PHP, aiming to “PHP-ize” a few useful pieces of the Golang HTTP package.
Golang-inspired HTTP helpers for PHP, including:
URL\Values container for query-style key/value listsext-jsoncomposer require dcarbone/gohttp
<?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"
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"
<?php declare(strict_types=1);
use DCarbone\Go\HTTP\HTTP;
$methods = [
HTTP::MethodGet,
HTTP::MethodPost,
HTTP::MethodPut,
HTTP::MethodPatch,
HTTP::MethodDelete,
];
<?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.
Install dependencies:
composer install
Run unit tests:
composer test
MIT
How can I help you explore Laravel packages today?