A collection of helper functions for your everyday work with http requests and responses.
- PSR-7 (
- Symfony HttpFoundation (
The main idea of these functions was to provide quick access to the http information during development (e.g. via the debugger console), that's why the functions are not namespaced. It's not meant to be used in your actual code! Srsly, it's not.
Here are some http-helper functions in action:
composer require-dev carstenwindler/http-helper
(I suggest to only add these functions as
The functions are registered using the composer autoload feature, so there is nothing more for you to do.
Symfony\Component\HttpFoundation\Request are supported by the following functions.
Serializes the request object in plain HTTP format according to RFC 7230.
Just like request_to_string(), but the request string will be stored in a file called
request.http in your DOCUMENT_ROOT.
This way you can e.g. easily execute the request using PhpStorms cool Editor-based Rest Client.
If the file already exists and is not empty, the request will be appended.
Returns the request object as cURL command, so it can be used e.g. on console or import it in Postman easily.
Symfony\Component\HttpFoundation\Response are supported by the following functions.
Serializes the response object in plain HTTP format according to RFC 7230.
response_to_string(), but the response string will be stored in a file called
response.http in your DOCUMENT_ROOT.
The following example shows you how to store requests and responses in files easily.
But why would you do that? Here, PhpStorm comes into play. It now comes equipped with the cool Editor-based Rest Client (think of it like a very simple Postman without all the fancy gui).
http-helper uses the suffix
.http, which is recognised by PhpStorm, so you will immediately have the possibility to modify and rerun the request in that file. I quite like the idea, since you could add it to your code base, so your fellow devs would have immediate access.
The serialization of the PSR-7 requests and responses are done using Zend Diactoros. Weird name, great library!
For Symfony, the build-in serializers are used. Nice.
- make storage path of