HTTPlug: HTTP client abstraction¶
HTTPlug allows you to write reusable libraries and applications that need an HTTP client without binding to a specific implementation. When all packages used in an application only specify HTTPlug, the application developers can choose the client that best fits their project and use the same client with all packages.
HTTPlug defines two HTTP client interfaces that we kept as simple as possible:
sendRequestmethod that sends a PSR-7
RequestInterfaceand either returns a PSR-7
ResponseInterfaceor throws an exception that implements
sendAsyncRequestmethod that sends a request asynchronously and always returns a
Http\Client\Promise. See Promise for more information.
PHP-HTTP offers two types of clients that implement the above interfaces:
Standalone clients that directly implement the interfaces.
Adapters that wrap existing HTTP client, such as Guzzle. These adapters act as a bridge between the HTTPlug interfaces and the clients that do not (yet) implement these interfaces.
Ideally, all HTTP client libraries out there will implement the HTTPlug interfaces. At that point, our adapters will no longer be necessary.
There are two main use cases for HTTPlug:
This project has been started by Eric Geloen as Ivory Http Adapter. It never made it to a stable release, but it relied on PSR-7 which was not stable either that time. Because of the constantly changing PSR-7, Eric had to rewrite the library over and over again (at least the message handling part, which in most cases affected every adapter as well).
In 2015, a decision has been made to move the library to its own organization, so PHP-HTTP was born.
See Migrating to HTTPlug for a guide how to migrate your code from the Ivory adapter.