Skip to main content

Installation

Install the package via Composer:
You also need at least one supported HTTP library. The default driver uses PHP’s built-in cURL extension, so if cURL is available you can start immediately. For other drivers, install the corresponding package:

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 an HttpClientConfig:
Or construct the config explicitly:
Or use the builder for more control:

Error Handling

HTTP requests can fail for many reasons. Wrap your calls in a try-catch block:
The exception hierarchy gives you granular control: 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’s withMock() method to supply predefined responses without making real HTTP calls:
The mock driver matches responses by URL and method, making it straightforward to verify that your application sends the right requests.

What’s Next

Now that you have a working client, explore the rest of the documentation: