Learn how to configure different HTTP clients using the Instructor HTTP client API.
HttpClientConfig
class encapsulates the configuration options for HTTP clients. Here’s a detailed breakdown of the available options:
Option | Type | Description | Default |
---|---|---|---|
httpClientType | string | Type of HTTP client to use | 'guzzle' |
connectTimeout | int | Connection timeout in seconds | 3 |
requestTimeout | int | Request timeout in seconds | 30 |
idleTimeout | int | Idle timeout in seconds (-1 for no timeout) | -1 |
Option | Type | Description | Default |
---|---|---|---|
maxConcurrent | int | Maximum number of concurrent requests in a pool | 5 |
poolTimeout | int | Timeout for the entire request pool in seconds | 60 |
Option | Type | Description | Default |
---|---|---|---|
failOnError | bool | Whether to throw exceptions on HTTP errors | true |
Option | Type | Description | Default |
---|---|---|---|
enabled | bool | Enable or disable HTTP debugging | false |
trace | bool | Dump HTTP trace information | false |
requestUrl | bool | Log the request URL | true |
requestHeaders | bool | Log request headers | true |
requestBody | bool | Log request body | true |
responseHeaders | bool | Log response headers | true |
responseBody | bool | Log response body | true |
responseStream | bool | Log streaming response data | true |
responseStreamByLine | bool | Log stream as complete lines (true) or raw chunks (false) | true |
withClient
method to select a different pre-configured client:
HttpClientConfig
object and apply it using the withConfig
method:
config/http.php
file for easy reference and maintenance.
'guzzle-short-timeout'
, 'guzzle-streaming'
) to make your code more readable and maintainable.
failOnError
based on how you want to handle errors. For critical operations, set it to true
to catch errors immediately. For bulk operations or request pools, set it to false
to handle errors individually.