VOOZH about

URL: https://deepwiki.com/hypervel/api-client/9-configuration-reference

⇱ Configuration Reference | hypervel/api-client | DeepWiki


Loading...
Menu

Configuration Reference

This document provides a comprehensive reference of all configuration options available in the hypervel/api-client package. Configuration operates at two levels: client-level settings defined through ApiClient properties, and request-level settings that override or extend the client configuration via PendingRequest methods.


Configuration Architecture

The API client uses a two-layer configuration architecture where settings flow from ApiClient to PendingRequest:

Configuration Layer Hierarchy


Sources: src/ApiClient.php14-116 src/PendingRequest.php22-342

Complete Configuration Properties

ApiClient Properties

PropertyTypeDefaultScopeDescription
$configDataObject|nullnullClientCustom configuration object for application-specific settings
$resourceclass-string<TResource>ApiResource::classClientDefault resource class for response transformation
$enableMiddlewarebooltrueClientMaster switch for middleware processing
$requestMiddlewarearray[]ClientOrdered list of request middleware class names
$responseMiddlewarearray[]ClientOrdered list of response middleware class names

Sources: src/ApiClient.php16-36

PendingRequest Properties

PropertyTypeDefaultScopeDescription
$resourceclass-string<TResource>InheritedRequestResource class for this request (overrides client default)
$enableMiddlewareboolInheritedRequestMiddleware enable flag for this request
$middlewareOptionsarray[]RequestOptions passed to middleware via context
$guzzleOptionsarray[]RequestGuzzle HTTP client configuration options
$requestMiddlewarearrayInheritedRequestRequest middleware for this request
$responseMiddlewarearrayInheritedRequestResponse middleware for this request
$requestClientPendingRequest|nullnullRequestCached HTTP client instance
$pipelinePipelineAuto-createdRequestMiddleware pipeline processor
$cachedMiddlewarearray (static)[]StaticCached middleware instances

Sources: src/PendingRequest.php27-51


Client-Level Configuration

The ApiClient class stores configuration that applies to all requests. Configuration is set by extending ApiClient and defining protected properties.

Configuration Object ($config)

The $config property stores application-specific configuration using DataObject from hypervel/support.

Property Details:

Usage Pattern:


Sources: src/ApiClient.php16-55 src/PendingRequest.php322

Resource Class ($resource)

The $resource property defines the class used to transform HTTP responses into typed resource objects.

Property Details:

Usage Pattern:


Sources: src/ApiClient.php22-63 src/PendingRequest.php29-290

Middleware Enable Flag ($enableMiddleware)

The $enableMiddleware property serves as a master switch for all middleware processing.

Property Details:

Sources: src/ApiClient.php26-91 src/PendingRequest.php274-288

Request Middleware ($requestMiddleware)

The $requestMiddleware property contains an ordered list of middleware classes that process requests before HTTP execution.

Property Details:

Usage Pattern:


Sources: src/ApiClient.php29-99 src/PendingRequest.php40-326

Response Middleware ($responseMiddleware)

The $responseMiddleware property contains an ordered list of middleware classes that process responses after HTTP execution.

Property Details:

Usage Pattern:


Sources: src/ApiClient.php33-107 src/PendingRequest.php45-326


Request-Level Configuration

PendingRequest instances inherit configuration from ApiClient and can override or extend settings on a per-request basis.

Configuration Inheritance

Configuration Copy Process


Sources: src/PendingRequest.php53-62 src/ApiClient.php112-115

Middleware Options ($middlewareOptions)

The $middlewareOptions property passes contextual data to middleware.

Property Details:

  • Type: array
  • Default: []
  • Method: withMiddlewareOptions(array $options) src/PendingRequest.php87-92
  • Context Injection: Attached via withContext('options', $middlewareOptions) src/PendingRequest.php296-304
  • Middleware Access: Retrieved via getContext('options') from request/response objects

Data Flow:


Usage Pattern:


Sources: src/PendingRequest.php33-304

Guzzle Options ($guzzleOptions)

The $guzzleOptions property configures the underlying Guzzle HTTP client.

Property Details:

Common Guzzle Options:

OptionTypeDescriptionExample
timeoutfloatTotal request timeout in seconds30.0
connect_timeoutfloatConnection timeout in seconds5.0
verifybool|stringSSL certificate verificationtrue or /path/to/cert.pem
proxystring|arrayHTTP proxy configuration'tcp://proxy.example.com:8080'
allow_redirectsbool|arrayRedirect behavior['max' => 5, 'strict' => true]
http_errorsboolThrow exceptions on 4xx/5xxfalse
headersarrayAdditional HTTP headers['User-Agent' => 'MyApp/1.0']
queryarrayQuery string parameters['page' => 1, 'limit' => 10]
jsonarrayJSON request body['name' => 'John']
form_paramsarrayForm-encoded request body['field' => 'value']
autharrayHTTP authentication['user', 'pass', 'basic']
certstring|arrayClient-side certificate'/path/to/cert.pem'
ssl_keystring|arraySSL private key'/path/to/key.pem'
debugbool|resourceDebug outputtrue

Application Flow:


Usage Pattern:


Sources: src/PendingRequest.php35-341

Resource Override (withResource())

The withResource() method overrides the client's default resource class for a specific request.

Method Details:

Usage Pattern:


Sources: src/PendingRequest.php29-290


Configuration Methods Reference

ApiClient Methods

Methods for accessing and modifying client-level configuration:

MethodSignatureReturn TypeLocationDescription
getConfig()getConfig()DataObject|nullsrc/ApiClient.php52-55Returns the custom configuration object
getResource()getResource()stringsrc/ApiClient.php60-63Returns the default resource class name
getEnableMiddleware()getEnableMiddleware()boolsrc/ApiClient.php68-71Returns whether middleware is enabled
enableMiddleware()enableMiddleware()staticsrc/ApiClient.php74-81Enables middleware processing, returns $this
disableMiddleware()disableMiddleware()staticsrc/ApiClient.php86-91Disables middleware processing, returns $this
getRequestMiddleware()getRequestMiddleware()arraysrc/ApiClient.php96-99Returns the request middleware array
getResponseMiddleware()getResponseMiddleware()arraysrc/ApiClient.php104-107Returns the response middleware array
getClient()getClient()PendingRequestsrc/ApiClient.php112-115Creates and returns a new PendingRequest instance

Sources: src/ApiClient.php48-115

PendingRequest Configuration Methods

Methods for per-request configuration overrides:

MethodSignatureReturn TypeLocationDescription
enableMiddleware()enableMiddleware()staticsrc/PendingRequest.php67-72Enables middleware for this request
disableMiddleware()disableMiddleware()staticsrc/PendingRequest.php77-82Disables middleware for this request
withMiddlewareOptions()withMiddlewareOptions(array $options)staticsrc/PendingRequest.php87-92Sets options passed to middleware
withGuzzleOptions()withGuzzleOptions(array $options)staticsrc/PendingRequest.php97-102Sets Guzzle HTTP client options
withRequestMiddleware()withRequestMiddleware(array $middleware)staticsrc/PendingRequest.php107-112Replaces request middleware array
withAddedRequestMiddleware()withAddedRequestMiddleware(array $middleware)staticsrc/PendingRequest.php117-122Appends to existing request middleware
withResponseMiddleware()withResponseMiddleware(array $middleware)staticsrc/PendingRequest.php127-132Replaces response middleware array
withAddedResponseMiddleware()withAddedResponseMiddleware(array $middleware)staticsrc/PendingRequest.php137-142Appends to existing response middleware
withResource()withResource(string $resource)staticsrc/PendingRequest.php150-167Sets resource class for this request
flushCache()flushCache()voidsrc/PendingRequest.php249-252Clears cached middleware instances

All methods except flushCache() return static to enable method chaining.

Sources: src/PendingRequest.php67-252

Middleware Array Methods

Detailed comparison of middleware array manipulation methods:

MethodEffectUse Case
withRequestMiddleware([...])Replaces entire arrayCompletely customize request middleware for one request
withAddedRequestMiddleware([...])Appends to existing arrayAdd additional request middleware while keeping client defaults
withResponseMiddleware([...])Replaces entire arrayCompletely customize response middleware for one request
withAddedResponseMiddleware([...])Appends to existing arrayAdd additional response middleware while keeping client defaults

Implementation Details:

Sources: src/PendingRequest.php107-142


Method Chaining Patterns

Configuration methods return static to enable fluent method chaining.

Method Chaining Flow


Chaining Examples:


Magic Method Delegation:

Sources: src/ApiClient.php41-45 src/PendingRequest.php67-263


Configuration Execution Flow

This diagram shows how configuration is applied during request execution:

Configuration Application Sequence


Sources: src/ApiClient.php112-115 src/PendingRequest.php53-341


Middleware Configuration Details

Enabling/Disabling Middleware

The $enableMiddleware flag provides a master switch for all middleware processing:

  • When true: Both request and response middleware pipelines execute src/PendingRequest.php274-288
  • When false: Middleware pipelines are skipped entirely

This can be toggled at the client level or per-request:


Middleware Class Lists

Middleware arrays contain class names as strings. The order matters as middleware executes sequentially:


Middleware classes are instantiated with the client's configuration object src/PendingRequest.php322 and cached to avoid repeated instantiation src/PendingRequest.php318-322

Middleware Options Context

Middleware options are attached to the request context before middleware execution:


Sources: src/PendingRequest.php31-307


Resource Class Configuration

The resource class transforms raw HTTP responses into application-specific objects. It must extend ApiResource:


The resource class is validated when set via withResource() src/PendingRequest.php152-162 and used to transform responses src/PendingRequest.php290

Sources: src/ApiClient.php22-63 src/PendingRequest.php29-290


Custom Configuration Object Pattern

The $config property uses DataObject from hypervel/support to store application-specific configuration:


Example implementation:


Sources: src/ApiClient.php16-55 src/PendingRequest.php322

Refresh this wiki

On this page