adampatterson / http
A simple Guzzle wrapper
1.0.0
2026-04-25 01:29 UTC
Requires
- guzzlehttp/guzzle: ^7.4
- illuminate/collections: ^v11.6.0
Requires (Dev)
- phpunit/phpunit: ^13.0
- psy/psysh: ^0.12.22
This package is auto-updated.
Last update: 2026-04-25 20:02:50 UTC
README
Note
This script is still under development.
Install from Packagist
composer require adampatterson/http
Usage
Basic Usage
use Http\Http; // GET request $response = Http::get('https://example.com/api/users'); // POST request with JSON $response = Http::asJson()->post('https://example.com/api/users', ['name' => 'John']); // POST request with form parameters $response = Http::asFormParams()->post('https://example.com/api/users', ['name' => 'John']); // Request with custom headers $response = Http::withHeaders(['X-Custom' => 'value'])->get('https://example.com/api/users'); // Request with Bearer token $response = Http::withToken('your-token')->get('https://example.com/api/users');
Response Helpers
The HttpResponse object provides several helpers to inspect the response:
$response->status(); // Get status code (int) $response->body(); // Get raw body (string) $response->json(); // Get JSON decoded body (array) $response->header('Content-Type'); // Get specific header $response->headers(); // Get all headers $response->isSuccess(); // 200-299 $response->isOk(); // Alias for isSuccess $response->isRedirect(); // 300-399 $response->isClientError(); // 400-499 $response->isServerError(); // 500+
Method Proxying
If you need to access a method on the underlying Guzzle response that is not explicitly defined in HttpResponse, it will be automatically proxied:
// getProtocolVersion() is not defined in HttpResponse, // so it is proxied to GuzzleHttp\Psr7\Response $version = $response->getProtocolVersion();
Tests
composer install
composer test
Code Coverage
To run tests with code coverage, ensure you have Xdebug installed and run:
composer test-coverage
Local Dev
Without needing to modify the composer.json file. Run from the theme root, this will symlink the package into the theme's vendor directory.
ln -s ~/Sites/packages/http/ ./vendor/adampatterson/http
Otherwise, you can add the local package to your composer.json file.
{
"repositories": [
{
"type": "path",
"url": "/Sites/packages/http"
}
]
}