switon/http-client

HTTP client contract with JSON-first helpers, typed failures, and pooled engines for Switon Framework

Maintainers

Package info

github.com/switon-php/http-client

Documentation

pkg:composer/switon/http-client

Statistics

Installs: 2

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-06 13:43 UTC

This package is auto-updated.

Last update: 2026-06-07 04:08:03 UTC


README

CI PHP 8.3+

Switon's JSON-first HTTP client for application services that need typed failures, lifecycle events, pooled host reuse, and response helpers.

Highlights

  • Pooled host reuse: repeated calls to the same host reuse the same pooled engine setup.
  • Single client entrypoint: HttpClientInterface gives app services one injectable HTTP client.
  • JSON-friendly defaults: shortcut methods and response parsing fit API-style calls.
  • Raw request support: non-JSON requests can still use the same client path.
  • Layered failures: transport, status, and parsing errors are separated.
  • Request tuning: timeout, proxy, TLS, CA, and pool size settings are centralized.
  • Lifecycle visibility: request activity is exposed through client events.

Installation

composer require switon/http-client

Quick Start

use Switon\Core\Attribute\Autowired;
use Switon\HttpClient\HttpClientInterface;

class UserService
{
    #[Autowired] protected HttpClientInterface $httpClient;

    public function createUser(array $data): array
    {
        return $this->httpClient
            ->post('https://api.example.com/users', $data)
            ->json();
    }
}

Docs: https://docs.switon.dev/latest/http-client

License

MIT.