fsilva / http-message
PSR Http Message compliant package
Installs: 1 608
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=5.4.0
- psr/http-message: 1.0.*@dev
Requires (Dev)
- phpunit/phpunit: 4.*
This package is auto-updated.
Last update: 2024-09-20 14:29:08 UTC
README
PSR Http Message compliant package. The goal is to have an HTTP message abstraction that can be used to implement a request/response strategy application.
This package is compliant with PSR-2 code standards and PSR-4 autoload standards. It also applies the semantic version 2.0.0 specification.
Installing via Composer
The recommended way to install Fsilva\HttpMessage
package is through
Composer.
# Install Composer curl -sS https://getcomposer.org/installer | php
You can add Fsilva\HttpMessage
package as a dependency using the composer.phar CLI:
$ composer require fsilva/http-message
Alternatively, you can Fsilva\HttpMessage
package as a dependency in your
project’s existing composer.json file:
{ "require": { "fsilva/http-message": "*" } }
Basic usage
Creating a very basic HTTP message
use Fsilva/HttpMessage/Message; use Fsilva/HttpMessage/Stream/Buffer; $message = new Message(); $body = new Buffer(); $body->write(json_encode(['some' => 'value'])); $request = $message->withProtocolVersion(Message::HTTP_1_1) ->withHeader('X-Requested-With', 'XMLHttpRequest') ->withHeader('User-Agent', 'PHP Request call') ->withBody($body) ->withoutHeader('pragma') ->withAddedHeader('X-Forwarded-For', ['client1', 'proxy1', 'proxy2']); $strMessage = "GET / HTTP/". $request->getProtocolVersion(); foreach($request->getHeaders() as $name => $values) { $strMessage .= "\n{$name}: ". implode(', ', $values); } // $strMessage is now a very simple HTTP message. $strMessage .= "\n\n". $request->getBody()->getContents();
Testing
$ vendor/bin/phpunit
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.