VOOZH about

URL: https://deepwiki.com/hypervel/http-client/11-api-reference

⇱ API Reference | hypervel/http-client | DeepWiki


Loading...
Menu

API Reference

This page provides comprehensive reference documentation for all public methods and properties across the Hypervel HTTP Client package. It is organized by class and includes method signatures, parameters, and return types.

For conceptual information about how these components work together, see Core Components. For practical usage examples, see Making HTTP Requests and Response Processing. For testing-specific functionality, see Testing and Mocking.


Class Overview


Sources: src/Factory.php1-526 src/PendingRequest.php1-1667 src/Request.php1-268 src/Response.php1-501 src/ResponseSequence.php1-132


Factory Class

The Factory class is the entry point for creating HTTP requests and managing the testing infrastructure.

Sources: src/Factory.php31-526

Creation and Configuration Methods

MethodSignatureDescription
__construct__construct(?EventDispatcherInterface $dispatcher = null)Creates a new Factory instance with optional event dispatcher
globalMiddlewareglobalMiddleware(callable $middleware): staticAdds middleware to apply to every request
globalRequestMiddlewareglobalRequestMiddleware(callable $middleware): staticAdds request-specific middleware to every request
globalResponseMiddlewareglobalResponseMiddleware(callable $middleware): staticAdds response-specific middleware to every request
globalOptionsglobalOptions(array|Closure $options): staticSets options to apply to every request
createPendingRequestcreatePendingRequest(): PendingRequestCreates a new PendingRequest instance with global configuration

Sources: src/Factory.php92-417

Static Factory Methods

MethodSignatureDescription
responseresponse(array|callable|int|PromiseInterface|Response|string|null $body = null, int $status = 200, array $headers = []): PromiseInterfaceCreates a fake response for testing
failedConnectionfailedConnection(?string $message = null): ClosureCreates a connection exception for testing

Sources: src/Factory.php138-170

Testing and Stubbing Methods

MethodSignatureDescription
fakefake(array|callable|null $callback = null): staticRegisters stub callbacks to intercept requests
fakeSequencefakeSequence(string $url = '*'): ResponseSequenceCreates and registers a response sequence for a URL pattern
sequencesequence(array $responses = []): ResponseSequenceCreates a new ResponseSequence instance
stubUrlstubUrl(string $url, array|callable|int|PromiseInterface|Response|string $callback): staticStubs a specific URL with a callback or response
preventStrayRequestspreventStrayRequests(bool $prevent = true): staticThrows exception if any request is not faked
preventingStrayRequestspreventingStrayRequests(): boolChecks if stray requests are being prevented
allowStrayRequestsallowStrayRequests(): staticAllows requests that are not faked
recordRequestResponsePairrecordRequestResponsePair(Request $request, ?Response $response): voidRecords a request/response pair for assertions
recordedrecorded(?callable $callback = null): CollectionGets recorded request/response pairs matching a callback

Sources: src/Factory.php172-399

Assertion Methods

MethodSignatureDescription
assertSentassertSent(callable $callback): voidAsserts a request matching the callback was sent
assertSentInOrderassertSentInOrder(array $callbacks): voidAsserts requests were sent in the given order
assertNotSentassertNotSent(callable $callback): voidAsserts a request matching the callback was not sent
assertNothingSentassertNothingSent(): voidAsserts no requests were sent
assertSentCountassertSentCount(int $count): voidAsserts the exact number of requests sent
assertSequencesAreEmptyassertSequencesAreEmpty(): voidAsserts all response sequences are empty

Sources: src/Factory.php308-382

Connection Management Methods

MethodSignatureDescription
registerConnectionregisterConnection(string $name, array $config = []): staticRegisters a named connection with configuration
getClientgetClient(?string $connection, HandlerStack $handlerStack, ?array $config = null): ClientInterfaceGets the HTTP client for a connection
createClientcreateClient(HandlerStack $handlerStack): ClientInterfaceCreates a new Guzzle client instance
getConnectionConfiggetConnectionConfig(string $name): arrayGets configuration for a specific connection
getConnectionConfigsgetConnectionConfigs(): arrayGets configuration for all connections
setConnectionConfigsetConnectionConfig(string $name, array $config): staticSets configuration for a specific connection

Sources: src/Factory.php436-513

Accessor Methods

MethodSignatureDescription
getDispatchergetDispatcher(): ?EventDispatcherInterfaceGets the current event dispatcher
getGlobalMiddlewaregetGlobalMiddleware(): arrayGets the array of global middleware

Sources: src/Factory.php420-433


PendingRequest Class

The PendingRequest class provides a fluent API for configuring and executing HTTP requests.

Sources: src/PendingRequest.php38-1667

Request Configuration Methods


Sources: src/PendingRequest.php212-521

MethodSignatureDescription
baseUrlbaseUrl(string $url): staticSets the base URL for the request
withUrlParameterswithUrlParameters(array $parameters = []): staticSets URL parameters for template substitution
withQueryParameterswithQueryParameters(array $parameters): staticSets query string parameters
withHeaderswithHeaders(array $headers): staticAdds headers to the request
withHeaderwithHeader(string $name, mixed $value): staticAdds a single header to the request
replaceHeadersreplaceHeaders(array $headers): staticReplaces headers on the request
contentTypecontentType(string $contentType): staticSets the Content-Type header
acceptaccept(string $contentType): staticSets the Accept header
acceptJsonacceptJson(): staticSets Accept header to application/json
withUserAgentwithUserAgent(bool|string $userAgent): staticSets the User-Agent header

Sources: src/PendingRequest.php212-407

Body Format Methods

MethodSignatureDescription
asJsonasJson(): staticIndicates the request contains JSON
asFormasForm(): staticIndicates the request contains form parameters
asMultipartasMultipart(): staticIndicates the request is multipart/form-data
withBodywithBody(StreamInterface|string $content, string $contentType = 'application/json'): staticAttaches a raw body to the request
attachattach(array|string $name, $contents = '', ?string $filename = null, array $headers = []): staticAttaches a file to the request
bodyFormatbodyFormat(string $format): staticSpecifies the body format of the request

Sources: src/PendingRequest.php223-299

Authentication Methods

MethodSignatureDescription
withBasicAuthwithBasicAuth(string $username, string $password): staticSets basic authentication credentials
withDigestAuthwithDigestAuth(string $username, string $password): staticSets digest authentication credentials
withTokenwithToken(string $token, string $type = 'Bearer'): staticSets an authorization token

Sources: src/PendingRequest.php369-397

Connection and Timeout Methods

MethodSignatureDescription
timeouttimeout(float|int $seconds): staticSets the request timeout in seconds
connectTimeoutconnectTimeout(float|int $seconds): staticSets the connection timeout in seconds
withCookieswithCookies(array $cookies, string $domain): staticSets cookies for the request
maxRedirectsmaxRedirects(int $max): staticSets the maximum number of redirects
withoutRedirectingwithoutRedirecting(): staticDisables following redirects
withoutVerifyingwithoutVerifying(): staticDisables TLS certificate verification
sinksink($to): staticSets the path where the response body should be stored
withOptionswithOptions(array $options): staticReplaces specified Guzzle options

Sources: src/PendingRequest.php420-521

Middleware Methods

MethodSignatureDescription
withMiddlewarewithMiddleware(callable $middleware): staticAdds middleware to the client handler stack
withRequestMiddlewarewithRequestMiddleware(callable $middleware): staticAdds request-specific middleware
withResponseMiddlewarewithResponseMiddleware(callable $middleware): staticAdds response-specific middleware
beforeSendingbeforeSending(callable $callback): staticAdds a callback to execute before sending

Sources: src/PendingRequest.php523-561

Retry Configuration Methods

MethodSignatureDescription
retryretry(array|int $times, Closure|int $sleepMilliseconds = 0, ?callable $when = null, bool $throw = true): staticConfigures retry behavior

Sources: src/PendingRequest.php493-508

Error Handling Methods

MethodSignatureDescription
throwthrow(?callable $callback = null): staticThrows exception on server or client error
throwIfthrowIf(bool|callable $condition): staticConditionally throws exception on error
throwUnlessthrowUnless(bool|callable $condition): staticThrows exception unless condition is true

Sources: src/PendingRequest.php563-591

HTTP Verb Methods


Sources: src/PendingRequest.php623-794

MethodSignatureDescription
getget(string $url, array|JsonSerializable|string|null $query = null): PromiseInterface|ResponseIssues a GET request
headhead(string $url, array|string|null $query = null): PromiseInterface|ResponseIssues a HEAD request
postpost(string $url, array|JsonSerializable $data = []): PromiseInterface|ResponseIssues a POST request
patchpatch(string $url, array $data = []): PromiseInterface|ResponseIssues a PATCH request
putput(string $url, array $data = []): PromiseInterface|ResponseIssues a PUT request
deletedelete(string $url, array $data = []): PromiseInterface|ResponseIssues a DELETE request
sendsend(string $method, string $url, array $options = []): PromiseInterface|ResponseSends a request with the given HTTP method

Sources: src/PendingRequest.php623-794

Asynchronous Methods

MethodSignatureDescription
asyncasync(bool $async = true): staticEnables asynchronous request mode
getPromisegetPromise(): ?PromiseInterfaceRetrieves the pending request promise

Sources: src/PendingRequest.php1235-1250

Testing Methods

MethodSignatureDescription
stubstub(callable|Collection $callback): staticRegisters stub callbacks to intercept requests
preventStrayRequestspreventStrayRequests(bool $prevent = true): staticThrows exception if request is not faked

Sources: src/PendingRequest.php1213-1232

Handler Stack Methods

MethodSignatureDescription
buildClientbuildClient(): ClientInterfaceBuilds the Guzzle client
buildHandlerStackbuildHandlerStack(): HandlerStackBuilds the Guzzle handler stack
pushHandlerspushHandlers(HandlerStack $handlerStack): HandlerStackAdds handlers to the handler stack
buildBeforeSendingHandlerbuildBeforeSendingHandler(): ClosureBuilds the before-sending handler
buildRecorderHandlerbuildRecorderHandler(): ClosureBuilds the recorder handler
buildStubHandlerbuildStubHandler(): ClosureBuilds the stub handler
runBeforeSendingCallbacksrunBeforeSendingCallbacks(RequestInterface $request, array $options): RequestInterfaceExecutes before-sending callbacks
mergeOptionsmergeOptions(...$options): arrayMerges options with current request options

Sources: src/PendingRequest.php1033-1202

Debugging Methods

MethodSignatureDescription
dumpdump(): staticDumps the request before sending
dddd(): staticDumps the request and exits

Sources: src/PendingRequest.php593-621

Connection Methods

MethodSignatureDescription
setConnectionsetConnection(?string $connection): staticSets the connection name
getConnectiongetConnection(): ?stringGets the current connection name
setConnectionConfigsetConnectionConfig(?array $config): staticSets the connection configuration
getConnectionConfiggetConnectionConfig(): ?arrayGets the connection configuration

Sources: src/PendingRequest.php1252-1294


Request Class

The Request class wraps PSR-7 RequestInterface and provides convenience methods for inspecting request data.

Sources: src/Request.php14-268

Inspection Methods

MethodSignatureDescription
methodmethod(): stringGets the HTTP method
urlurl(): stringGets the request URL
hasHeaderhasHeader(string $key, mixed $value = null): boolChecks if request has a header
hasHeadershasHeaders(array|string $headers): boolChecks if request has multiple headers
headerheader(string $key): arrayGets values for a header
headersheaders(): arrayGets all request headers
bodybody(): stringGets the request body as string
hasFilehasFile(string $name, ?string $value = null, ?string $filename = null): boolChecks if request contains a file

Sources: src/Request.php30-122

Data Access Methods

MethodSignatureDescription
datadata(): arrayGets the request data (form or JSON)
queryquery(): arrayGets the query string parameters
withDatawithData(array $data): RequestSets decoded data on the request
withQuerywithQuery(array $query = []): RequestMerges query parameters

Sources: src/Request.php124-215

Content Type Detection Methods

MethodSignatureDescription
isFormisForm(): boolChecks if request is form-encoded
isJsonisJson(): boolChecks if request is JSON
isMultipartisMultipart(): boolChecks if request is multipart

Sources: src/Request.php165-189

Conversion Methods

MethodSignatureDescription
toPsrRequesttoPsrRequest(): RequestInterfaceGets the underlying PSR-7 request

Sources: src/Request.php217-223

ArrayAccess Implementation

MethodSignatureDescription
offsetExistsoffsetExists($offset): boolChecks if data key exists
offsetGetoffsetGet($offset): mixedGets data by key
offsetSetoffsetSet($offset, mixed $value): voidThrows LogicException (read-only)
offsetUnsetoffsetUnset($offset): voidThrows LogicException (read-only)

Sources: src/Request.php225-267


Response Class

The Response class wraps PSR-7 ResponseInterface and provides methods for extracting and inspecting response data.

Sources: src/Response.php25-501

Data Extraction Methods


Sources: src/Response.php58-152

MethodSignatureDescription
bodybody(): stringGets the response body as string
jsonjson(?string $key = null, mixed $default = null): mixedGets JSON-decoded body as array
objectobject(): array|object|nullGets JSON-decoded body as object
collectcollect(?string $key = null): CollectionGets JSON-decoded body as Collection
fluentfluent(?string $key = null): FluentGets JSON-decoded body as Fluent object
resourceresource()Gets body as PHP resource
decodeUsingdecodeUsing(?Closure $callback): staticSets a custom decode callback

Sources: src/Response.php59-152

Header Methods

MethodSignatureDescription
headerheader(string $header): stringGets a single header value
headersheaders(): arrayGets all response headers

Sources: src/Response.php154-168

Status Methods

MethodSignatureDescription
statusstatus(): intGets the HTTP status code
reasonreason(): stringGets the reason phrase
effectiveUrieffectiveUri(): ?UriInterfaceGets the effective URI after redirects
successfulsuccessful(): boolChecks if status is 2xx
redirectredirect(): boolChecks if status is 3xx
failedfailed(): boolChecks if client or server error
clientErrorclientError(): boolChecks if status is 4xx
serverErrorserverError(): boolChecks if status is 5xx

Sources: src/Response.php170-232

Status Code Checking Methods (via DeterminesStatusCode Trait)

The following methods are provided by the DeterminesStatusCode trait:

MethodDescription
ok()Status code 200
created()Status code 201
accepted()Status code 202
noContent()Status code 204
movedPermanently()Status code 301
found()Status code 302
badRequest()Status code 400
unauthorized()Status code 401
paymentRequired()Status code 402
forbidden()Status code 403
notFound()Status code 404
requestTimeout()Status code 408
conflict()Status code 409
unprocessableEntity()Status code 422
tooManyRequests()Status code 429
serverError()Status code 500

Sources: src/Concerns/DeterminesStatusCode.php1-143

Error Handling Methods

MethodSignatureDescription
onErroronError(callable $callback): staticExecutes callback if there was an error
toExceptiontoException(): ?RequestExceptionCreates exception from response
throwthrow(): staticThrows exception if error occurred
throwIfthrowIf(bool|Closure $condition): staticConditionally throws exception
throwIfStatusthrowIfStatus(callable|int $statusCode): staticThrows exception if status matches
throwUnlessStatusthrowUnlessStatus(callable|int $statusCode): staticThrows exception unless status matches
throwIfClientErrorthrowIfClientError(): staticThrows exception if 4xx status
throwIfServerErrorthrowIfServerError(): staticThrows exception if 5xx status

Sources: src/Response.php234-373

Metadata Methods

MethodSignatureDescription
cookiescookies(): CookieJarGets the response cookies
handlerStatshandlerStats(): arrayGets handler statistics
closeclose(): staticCloses the response stream

Sources: src/Response.php247-270

Conversion Methods

MethodSignatureDescription
toPsrResponsetoPsrResponse(): ResponseInterfaceGets underlying PSR-7 response
__toString__toString()Converts response to string (body)

Sources: src/Response.php272-485

Debugging Methods

MethodSignatureDescription
dumpdump(?string $key = null): staticDumps response content
dddd(?string $key = null): voidDumps response content and exits
dumpHeadersdumpHeaders(): staticDumps response headers
ddHeadersddHeaders()Dumps response headers and exits

Sources: src/Response.php375-431

ArrayAccess Implementation

MethodSignatureDescription
offsetExistsoffsetExists($offset): boolChecks if JSON key exists
offsetGetoffsetGet($offset): mixedGets JSON value by key
offsetSetoffsetSet($offset, mixed $value): voidThrows LogicException (read-only)
offsetUnsetoffsetUnset($offset): voidThrows LogicException (read-only)

Sources: src/Response.php433-475


ResponseSequence Class

The ResponseSequence class manages ordered sequences of responses for testing purposes.

Sources: src/ResponseSequence.php12-132

Construction Methods

MethodSignatureDescription
__construct__construct(protected array $responses)Creates a new response sequence
pushpush(array|string|null $body = null, int $status = 200, array $headers = []): staticAdds a response to the sequence
pushStatuspushStatus(int $status, array $headers = []): staticAdds a response with status code
pushFilepushFile(string $filePath, int $status = 200, array $headers = []): staticAdds a response from file contents
pushFailedConnectionpushFailedConnection(?string $message = null): staticAdds a connection failure
pushResponsepushResponse(mixed $response): staticAdds a raw response

Sources: src/ResponseSequence.php27-84

Configuration Methods

MethodSignatureDescription
whenEmptywhenEmpty(Closure|PromiseInterface $response): staticSets default response when empty
dontFailWhenEmptydontFailWhenEmpty(): staticReturns default response when empty
isEmptyisEmpty(): boolChecks if sequence is depleted

Sources: src/ResponseSequence.php86-111

Invocation

MethodSignatureDescription
__invoke__invoke(Request $request): mixedGets next response in sequence

Sources: src/ResponseSequence.php113-131


Method Call Flow Diagram


Sources: src/Factory.php404-525 src/PendingRequest.php187-210 src/PendingRequest.php713-794


Macroable Methods

All major classes (Factory, PendingRequest, Request, Response, ResponseSequence) use the Macroable trait, which enables runtime method extension:

MethodSignatureDescription
macromacro(string $name, object|callable $macro)Registers a custom macro
mixinmixin(object $mixin, bool $replace = true)Mixes another object's methods
hasMacrohasMacro(string $name): boolChecks if macro exists
flushMacrosflushMacros(): voidRemoves all macros

Sources: src/Factory.php17-36 src/PendingRequest.php40-41 src/Request.php16 src/Response.php27-29 src/ResponseSequence.php14


Public Properties

PendingRequest Public Properties

None. All properties are protected or private.

Response Public Properties

PropertyTypeDescription
$cookies?CookieJarThe request cookies
$transferStats?TransferStatsTransfer statistics for the request

Sources: src/Response.php43-49

Request Public Properties

None. All properties are protected or private.


Property Access Diagram


Sources: src/Response.php43-260

Refresh this wiki

On this page