A fast PHP7 implementation of PSR-7
A super lightweight PSR-7 implementation. Very strict and very fast.
|Lines of code||3 000||3 000||1 700||1 000|
* Percent of completed tests in https://github.com/php-http/psr7-integration-tests
** See benchmark at https://github.com/Nyholm/http-client-benchmark (higher is better)
composer require nyholm/psr7
If you are using Symfony Flex then you get all message factories registered as services.
The PSR-7 objects do not contain any other public methods than those defined in the PSR-7 specification.
Use the PSR-17 factory to create requests, streams, URIs etc.
$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory(); $request = $psr17Factory->createRequest('GET', 'http://tnyholm.se'); $stream = $psr17Factory->createStream('foobar');
With HTTPlug or any other PSR-18 (HTTP client) you may send requests like:
composer require kriswallsmith/buzz
$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory(); $psr18Client = new \Buzz\Client\Curl($psr17Factory); $request = $psr17Factory->createRequest('GET', 'http://tnyholm.se'); $response = $psr18Client->sendRequest($request);
nyholm/psr7-server package can be used
to create server requests from PHP superglobals.
composer require nyholm/psr7-server
$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory(); $creator = new ServerRequestCreator( $psr17Factory, // ServerRequestFactory $psr17Factory, // UriFactory $psr17Factory, // UploadedFileFactory $psr17Factory // StreamFactory ); $serverRequest = $creator->fromGlobals();
composer require zendframework/zend-httphandlerrunner
$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory(); $responseBody = $psr17Factory->createStream('Hello world'); $response = $psr17Factory->createResponse(200)->withBody($responseBody); (new \Zend\HttpHandlerRunner\Emitter\SapiEmitter())->emit($response);
This package is currently maintained by Tobias Nyholm and Martijn van der Ven. They have decided that the goal of this library should be to provide a super strict implementation of PSR-7 that is blazing fast.
The package will never include any extra features nor helper methods. All our classes and functions exist because they are required to fulfill the PSR-7 specification.