Skip to content

switon-php/http-client

Repository files navigation

Switon HTTP Client Package

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.

About

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

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages