Skip to content

v3.1.0

Choose a tag to compare

@Thavarshan Thavarshan released this 11 May 21:10
· 75 commits to main since this release

Added

  • PSR-18 Client: Fetch\Http\Client now implements Psr\Http\Client\ClientInterface for drop-in interoperability.

  • Fluent Request Builder: Chainable helpers on ClientHandler for headers, query params, JSON/form/multipart bodies, bearer token, basic auth, timeouts, redirects, cookies, proxy, certificates.

  • Async/Promise Support: Built-in ReactPHP-style promises (async(), await(), all(), race(), any(), sequence()), with ->async() toggle and wrapAsync()/awaitPromise() helpers.

  • Automatic Retries: Configurable max retries, retry delay, exponential backoff with jitter, and retry-on-status (408, 429, 5xx) or exceptions (ConnectException).

  • PSR-3 Logging: Optional LoggerInterface injection on Client and ClientHandler with info/debug/error logs and sensitive-data masking for retries, requests, and responses.

  • Immutable PSR-7 Extensions:

    • Fetch\Http\Request extends Guzzle’s PSR-7 Request with immutability traits and JSON/form/multipart constructors.
    • Fetch\Http\Response extends Guzzle’s PSR-7 Response with buffered body, array-access to JSON payloads, and helpers: ->json(), ->text(), ->xml(), ->blob(), ->arrayBuffer(), status inspectors, etc.
  • Enums for Safety: Fetch\Enum\Method, ContentType, and Status enums for validating methods, content types, and status codes.

  • Test Helpers: ClientHandler::createMockResponse() and createJsonResponse() to easily stub HTTP responses in unit tests.

Changed

  • Consolidated Handler Traits: Core behavior refactored into six concerns (ConfiguresRequests, HandlesUris, ManagesPromises, ManagesRetries, PerformsHttpRequests, SendsRequests) for clearer separation of URI handling, retries, promises, and request dispatch.
  • Unified Fetch API: Client::fetch() now returns either a ResponseInterface or the handler for method chaining, replacing older ad-hoc patterns.
  • Error-handling Alignment: Top-level Client::sendRequest() now throws standardized NetworkException, RequestException, or ClientException instead of raw RuntimeException.
  • Default Options Management: Moved default method, headers, and timeout into ClientHandler::$defaultOptions with new getDefaultOptions() and setDefaultOptions().
  • Guzzle Configuration: ClientHandler now reuses a single Guzzle client instance with RequestOptions::HTTP_ERRORS disabled (handling errors internally) and CONNECT_TIMEOUT mapped from handler timeout.