PSR-18: HTTP Client

PSR-18: the standard PHP interface for HTTP clients, decoupling code from any specific HTTP client implementation.

Library
Composer
v1.0.3
1,721stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
41/100Fair
Development Activity0
Maintenance20
Community44
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
82/100Excellent
Architecture90
Code Quality85
Innovation55
Learning Curve98

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 implements
  • ClientExceptionInterface — the base exception interface every HTTP client related exception must implement
  • RequestExceptionInterface — thrown when a request itself is invalid or malformed, exposing getRequest()
  • 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\ClientInterface so 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 ClientInterface instead 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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search