Download the PHP package zlodes/http-client without Composer

On this page you can find all versions of the php package zlodes/http-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package http-client

zlodes/http-client

Observable, type-safe HTTP client for PHP 8.4+.

Generic Request<TResponse> ensures $client->send(request: $request) returns the correct response type — verified by PHPStan at max level.

Features

Installation

You'll also need a PSR-7 implementation and any PSR-18 HTTP client, for example:

Optional integrations such as logging and metrics are up to your application and middleware choices.

Quick Start

Define a request

Define a response

Implement a hydrator

Wire it together

Empty Response (Fire-and-Forget Requests)

For requests that don't return a meaningful body (e.g., DELETE, PUT that returns 204), use EmptyResponse to skip hydration entirely:

The client detects EmptyResponse and returns a shared singleton instance — no hydrator is invoked, no deserialization happens.

Collection Responses

For endpoints that return a JSON array of items (e.g. GET /users → [{...}, {...}]), implement CollectionRequest<TItem> to get a typed, iterable response without writing a per-endpoint wrapper.

Branch on CollectionRequest inside your hydrator and use CollectionResponse::fromHydrated() to build a typed response from a denormalizer payload of unknown shape — it validates the array shape and the element types at runtime and gives you back a CollectionResponse<TItem> without manual @var casts:

Per-Request Hydration Override

For APIs that need custom parsing, implement HasResponseHydrator on the request:

The client checks for HasResponseHydrator first, then falls back to the default hydrator.

Error Responses

HttpClient::send() treats 4xx/5xx responses as failures. Register ErrorResponseHandler implementations to turn those responses into typed exceptions.

Register handlers globally on the client, after the middleware array:

Or per request with HasErrorResponseHandlers; request-level handlers are checked before client-level ones.

Timeouts

Timeouts travel with the request as a TransportOptions value. null means "not set here" and never overwrites a value set earlier, so precedence is always the same: request > client > global default.

For a single endpoint, implement HasTransportOptions. Those values win over everything else:

WithTimeout only adds a TimeoutMiddleware to the pipeline, so the same behaviour is available without the factory:

The bundled Psr18Transport ignores them. PSR-18 has no per-request options, so configure timeouts on the wrapped client instead. To honour per-request options, implement your own Transport and read them from the TransportOptions argument. Throw TransportTimeoutException (extends TransportException) on timeout so callers can tell a timeout from a refused connection.

Default headers

Each option sets one header. Stack them for more. If the request already has that header, the caller's value is left as-is. Header names are matched case-insensitively.

WithHeader only adds a HeaderMiddleware to the pipeline, so the same behaviour is available without the factory:

Middleware

Middleware follows an onion model. Each middleware receives a RequestContext and a RequestHandler $next:

Logging example

Metrics example

Wire them in by passing middleware instances to HttpClient:

ClientFactory

For applications with multiple API clients sharing common configuration (transport, logging middleware, hydrator), use ClientFactory with composable options instead of constructing HttpClient directly.

Available options

Option Behavior
WithTransport(Transport) Sets the transport (last-writer-wins)
WithResponseHydrator(ResponseHydrator) Sets the hydrator (last-writer-wins)
WithMiddleware(Middleware ...) Appends middlewares (additive)
WithErrorResponseHandler(ErrorResponseHandler ...) Appends error handlers (additive)
WithBaseUri(UriInterface) Sets the base URI (last-writer-wins)
WithTimeout(?timeout, ?connectTimeout) Appends a TimeoutMiddleware (additive)
WithHeader(name, value) Appends a HeaderMiddleware (additive)

Defaults are applied first, then make() options on top. Last-writer-wins options can be overridden per client; additive options accumulate across defaults and make() calls.

Custom client creator

Pass a custom closure to control how HttpClient is instantiated:

Architecture

Development


All versions of http-client with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
psr/http-client Version ^1.0
psr/http-message Version ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package zlodes/http-client contains the following files

Loading the files please wait ...