HTTPlug
The HTTP client abstraction for PHP, letting libraries depend on an interface instead of a concrete client.
Repository Health
Technical Analysis
HTTPlug is an HTTP client abstraction for PHP built on PSR-7 HTTP messages. It defines a small set of interfaces - a synchronous HttpClient and an asynchronous HttpAsyncClient - that libraries can depend on instead of tying themselves to a specific HTTP client implementation like Guzzle or cURL. Consumers of those libraries are then free to plug in whichever client they prefer.
Historically the predecessor of the PSR-18 standard, HTTPlug remains widely used across the PHP ecosystem for decoupling packages from concrete transport code. Its HttpClient interface mirrors the PSR-18 signature, while the HttpAsyncClient adds promise-based asynchronous requests, and a companion exception hierarchy standardizes network and HTTP error handling.
What You Get
- A synchronous HttpClient interface matching the PSR-18 sendRequest signature
- An HttpAsyncClient interface for promise-based asynchronous requests
- A standardized exception hierarchy for network, request, and transfer errors
- PSR-7 message compatibility so it works with any conforming HTTP message library
- Promise interfaces for composing asynchronous HTTP calls
Common Use Cases
- Writing an SDK or library that must send HTTP requests without forcing a client on users
- Decoupling application code from Guzzle, cURL, or other concrete HTTP clients
- Supporting both synchronous and asynchronous HTTP calls behind one abstraction
Under The Hood
Architecture - HTTPlug is an interface-only package under the Http\Client\ namespace. The core contracts are HttpClient::sendRequest() (mirroring PSR-18) and HttpAsyncClient::sendAsyncRequest(), which returns a promise. The src/Promise directory ships HttpFulfilledPromise and HttpRejectedPromise implementations of the php-http/promise contract, and src/Exception defines a hierarchy - TransferException at the root, with HttpException, NetworkException, and RequestException plus a RequestAwareTrait - so all client failures share a common type.
Tech Stack - Pure PHP supporting 7.1 through 8.x, depending only on psr/http-client, psr/http-message, and php-http/promise. Autoloading is PSR-4, and there are no heavyweight runtime dependencies because the package intentionally contains contracts rather than an implementation.
Code Quality - Specifications are written with phpspec (spec/ directory) and static analysis is enforced via PHPStan (phpstan.neon.dist with a baseline). The surface is deliberately tiny and stable, reflecting years of production use across the php-http ecosystem, though day-to-day development activity is now low since the abstraction is essentially complete.
API Design - The API is minimal and idiomatic: a single-method synchronous interface plus an asynchronous counterpart, with signatures aligned to PSR standards so migration is trivial. Because it only defines interfaces, adopters pair it with a client adapter (for example a Guzzle or Symfony adapter) and program against the interface, keeping their own code transport-agnostic.