HttpRequest value object. You construct it with explicit parameters — URL, method, headers, body, and options — and pass it to HttpClient::send(). There are no magic methods or implicit state; what you see is what gets sent.
Request Structure
TheHttpRequest constructor accepts five named parameters:
| Parameter | Type | Description |
|---|---|---|
url | string | The full URL including any query parameters |
method | string | The HTTP method (GET, POST, PUT, PATCH, DELETE, etc.) |
headers | array | Associative array of header name to value |
body | string|array | Request body — arrays are JSON-encoded automatically; strings are sent verbatim |
options | array | Driver-level options (e.g., ['stream' => true]) |
id and timestamped with createdAt and updatedAt properties automatically.
GET Requests
GET requests are the simplest form. Pass query parameters directly in the URL:POST with JSON Body
When you pass an array as the body, it is automatically JSON-encoded through theHttpRequestBody class:
PUT, PATCH, and DELETE
All HTTP methods work the same way. Just change the method string:Setting Headers
Headers are passed as a flat associative array. Common headers include authentication tokens, content types, and custom application headers:Modifying Requests
HttpRequest is immutable. The with*() methods return a new instance with the modification applied:
HttpRequestBody, which provides toString() and toArray() conversions:
Streaming Option
To enable streaming on a request, either set thestream option in the constructor or use withStreaming():
isStreamed() returns true, calling stream() on the PendingHttpResponse will yield chunks as they arrive instead of buffering the entire response.