This package is to allow you to create HTTP Messages in PHP, in a simple and reliable way.
composer require http-php/message
To use this package, it is very simple. Create a message using the following code:
use HttpPHP\Message\Message;
$message = Message::make(
payload: ['test' => 'payload'],
);
// Add a header
$message->withHeader(
key: 'Authorization',
value: 'Bearer some-super-secret-token',
);
// Fetch the header value
$message->header(
key: 'Authorization',
)->toString(); // 'Bearer some-super-secret-token'
// Fetch all headers
$message->headers();
// Fetch the payload
$message->payload()->parse(); // Returns an array representation of the payload.
$message->payload()->body(); // Returns the raw payload you wish to send.
To run the test suite:
composer run test
The MIT LIcense (MIT). Please see License File for more information.