nategood/httpful
Chainable PHP HTTP client for making REST requests with minimal boilerplate. Supports JSON/XML parsing, automatic serialization, custom headers, auth, redirects, and file uploads. Includes helpful debugging and response wrappers for quick API integrations.
Install via Composer: composer require nategood/httpful. Begin with a simple GET request to fetch and parse JSON from an API:
$response = \Httpful\Request::get('https://api.example.com/users')
->expectsJson()
->send();
foreach ($response->body->users as $user) {
echo $user->name . "\n";
}
Start here: the README includes basic examples; explore the examples/ directory if present in the repo for patterns like authentication or POSTing form data.
\Httpful\Request::post('https://api.example.com/users')
->sendsJson()
->body(['name' => 'Bob'])
->addHeader('Authorization', "Bearer {$token}")
->timeout(15)
->send();
->sendsJson(), ->sendsFormUrlEncoded(), and ->expectsJson() to auto-set headers and deserialize responses—no manual json_encode() or json_decode() needed.$response->body, raw string with $response->raw_body, HTTP status code via $response->code, and headers via $response->headers.Httpful\Request in a service class (e.g., UserService) and mock the client in tests:
$mockResponse = Mockery::mock(\Httpful\Response::class);
$mockResponse->shouldReceive('body')->andReturn((object)['id' => 123]);
$client = Mockery::mock(\Httpful\Request::class);
$client->shouldReceive('send')->andReturn($mockResponse);
Httpful\Client::registerHandler() for advanced protocol support (e.g., mocking in test environments).^1.0) and verify PHP 8.x compatibility—some users report issues with strict error reporting or json_decode strictness.SSL: handshake timed out or silent failures, configure cURL options explicitly:
->options(['curl' => [
CURLOPT_TIMEOUT => 10,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2
]])
->expects('application/json') to enforce JSON parsing or fallback to ->raw_body for non-standard formats. For XML, use ->expectsXml() and access via $response->body->xpath(...).try { ... } catch (\Exception $e) { retry(...) }), as the client offers no exponential backoff.Http:: client (Guzzle-based) instead. This package is best reserved for legacy integrations, CLI scripts, or where minimal dependencies are critical.How can I help you explore Laravel packages today?