switon / http-client
HTTP client contract with JSON-first helpers, typed failures, and pooled engines for Switon Framework
v1.0.0
2026-06-06 13:43 UTC
Requires
- php: >=8.3
- ext-curl: *
- psr/event-dispatcher: ^1.0
- switon/command: ^1.0
- switon/core: ^1.0
- switon/event: ^1.0
- switon/pool: ^1.0
Requires (Dev)
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- switon/testing: ^1.0
README
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:
HttpClientInterfacegives 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.