Learn how to create and send HTTP requests using the Instructor HTTP client API.
HttpRequest
class, which encapsulates the various components of an HTTP request.
HttpRequest
takes several parameters:
url
: The URL to send the request to (string)method
: The HTTP method to use (string)headers
: An associative array of HTTP headers (array)body
: The request body, which can be a string or an array (mixed)options
: Additional options for the request (array)with*
methods return a new request instance rather than modifying the original one.
HttpClientRequest
constructor. The library supports all standard HTTP methods:
Content-Type
header to application/json
.
HttpRequestBody
class, which provides methods to access the body in different formats:
options
parameter allows you to specify additional options for the request:
stream
: When set to true
, enables streaming response handling