http-php/messages

A simple OOP wrapper to work with HTTP messages in PHP

dev-main 2023-02-06 12:02 UTC

This package is auto-updated.

Last update: 2024-12-06 15:51:18 UTC


README

Latest Version PHP Version Tests Total Downloads

This package is to allow you to create HTTP Messages in PHP, in a simple and reliable way.

Installation

composer require http-php/message

Usage

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.

Testing

To run the test suite:

composer run test

Credits

LICENSE

The MIT LIcense (MIT). Please see License File for more information.