Installation
Install the package via Composer:Requirements
- PHP 8.2 or higher
- JSON extension
- cURL extension (included by default in most PHP installations)
Sending Your First Request
Using the HTTP client involves three steps: create a client, build a request, and read the response.HttpClient::default() creates a client with the default cURL driver. The send() method returns a PendingHttpResponse, which is lazy — the network call does not happen until you call get() or stream().
Choosing a Driver
If you want a specific driver, use a preset name or pass anHttpClientConfig:
Error Handling
HTTP requests can fail for many reasons. Wrap your calls in a try-catch block:
When
failOnError is set to true in the config, the client throws typed exceptions for 4xx and 5xx responses automatically. When it is false (the default), you need to check the status code yourself.
Testing with Mocks
For tests, use the builder’swithMock() method to supply predefined responses without making real HTTP calls:
What’s Next
Now that you have a working client, explore the rest of the documentation:- Making Requests — learn about request construction, HTTP methods, headers, and bodies.
- Handling Responses — read buffered content, inspect headers, and decode JSON.
- Streaming Responses — consume chunked data as it arrives.
- Middleware — add retry logic, circuit breakers, and custom behaviors.