PSR-18: HTTP Client
PSR-18: the standard PHP interface for HTTP clients, decoupling code from any specific HTTP client implementation.
Repository Health
Technical Analysis
psr/http-client is the official PHP-FIG package defining PSR-18, the standard interface for synchronous HTTP clients in PHP. It contains no implementation of its own — only the ClientInterface (a single sendRequest(RequestInterface): ResponseInterface method built on PSR-7 request/response objects) plus a small hierarchy of exception interfaces (ClientExceptionInterface, RequestExceptionInterface, NetworkExceptionInterface) that HTTP client implementations must throw.
By depending on psr/http-client instead of a concrete HTTP client library, PHP packages and applications can accept any PSR-18-compliant client (Guzzle, Symfony HttpClient, Buzz, and others) as a dependency, letting consumers swap implementations without changing calling code — the same interoperability pattern PSR-7 (messages) and PSR-17 (factories) establish for the rest of the HTTP stack.
What You Get
ClientInterface::sendRequest(RequestInterface $request): ResponseInterface— the single method every PSR-18 client implementsClientExceptionInterface— the base exception interface every HTTP client related exception must implementRequestExceptionInterface— thrown when a request itself is invalid or malformed, exposinggetRequest()NetworkExceptionInterface— thrown when no response was received due to network failure (DNS, connection refused, etc.)
Common Use Cases
- SDK and library authors type-hint against
Psr\Http\Client\ClientInterfaceso consumers can inject Guzzle, Symfony HttpClient, or any other PSR-18 implementation - Dependency injection containers wiring an application’s HTTP client as an interchangeable, swappable service
- Testing code that mocks
ClientInterfaceinstead of a specific HTTP client’s concrete class - Framework-agnostic packages that need to make outbound HTTP calls without forcing a particular HTTP client dependency on consumers
Under The Hood
Architecture — the package is deliberately minimal: four interfaces in src/ (ClientInterface, ClientExceptionInterface, RequestExceptionInterface, NetworkExceptionInterface) with no classes, no logic, and no runtime behavior — it is a pure contract package that other packages implement or depend on. Tech Stack — plain PHP 7/8 compatible interfaces with a single dependency on psr/http-message (PSR-7) for the RequestInterface/ResponseInterface types referenced in method signatures; there is no build step, no compiled artifact, and no test suite because there’s no executable logic to test. Code Quality — as a PHP-FIG standards package, quality is measured by specification stability rather than test coverage: the interfaces have been frozen since the 1.0 release (28 total commits across the repo’s history) and are governed by the PHP-FIG voting process, meaning breaking changes are extremely rare and require a formal PSR revision. API Design — the entire public surface is one method (sendRequest) and three exception interfaces, which is the point: PSR-18’s minimalism is what makes it easy for both HTTP client authors and library consumers to adopt, since implementing or depending on the interface requires understanding a single method signature.
Used by 3 apps in this directory
Fern
Developer Tools
Fern turns a single OpenAPI, AsyncAPI, or Protobuf definition into type-safe SDKs for nine languages and a hosted API documentation site, all from one CLI and one source of truth.
Firecrawl
AI Development · Developer Tools
Turn any website into clean, LLM-ready data with a single API call — no proxy headaches, no scraping complexity.
wallabag
Bookmarks Archiving
Self-hosted read-it-later app that saves clean, ad-free articles from any webpage for distraction-free reading across all your devices.