sabre/http 2.0 released
Last week we released a new open source library, sabre/http.
This library makes working with HTTP-related features in PHP a lot easier. The package was actually embedded into sabre/dav for nearly 5 years, but this is the first time it's released stand-alone.
Some technical details
As a PHP developer, you often touch upon HTTP. Usually, because your PHP application is running on a HTTP server.
PHP provides several mechanisms to access information about the PHP request,
php://input, and several
mechanisms to influence the response, such as
All of these are 'global'. Meaning that there is only one of them per PHP request, which makes sense, as a PHP script tends to only live for the lifetime of a single HTTP request.
Purely depending on these global mechanisms can cause issues though. If you'd like to unittest these you will be modifying globals (generally not a recommended practice), or in a situation where you want to do a sub-request in a request (not entirely uncommon in many frameworks), the sub-request may now modify the state of the top-level request.
If you're already deep into OOP, sabre/http provides a OOP wrapper around the request and response. This can potentially make your application more robust, but also provides a much more elegant way of dealing with requests and responses in php.
The package also provides a rudimentary client, that actually uses the exact same Request and Response objects.
The client wraps around Curl, and allows you to make HTTP requests asynchronously.
A side-effect of using the same request and response objects for both the server and the client, is that it actually becomes really easy to create a simple reverse proxy.
The full documentation can be found on the github project page.
We hope you like it as much as we do. If you're using this new package in any way, we would love to hear from you.