• Stars
    star
    1,061
  • Rank 43,495 (Top 0.9 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A super lightweight PSR-7 implementation

PSR-7 implementation

Latest Version Total Downloads Monthly Downloads Software License Static analysis Tests

A super lightweight PSR-7 implementation. Very strict and very fast.

Description Guzzle Laminas Slim Nyholm
Lines of code 3.300 3.100 1.900 1.000
PSR-7* 66% 100% 75% 100%
PSR-17 No Yes Yes Yes
HTTPlug No No No Yes
Performance (runs per second)** 14.553 14.703 13.416 17.734

* Percent of completed tests in https://github.com/php-http/psr7-integration-tests

** Benchmark with 50.000 runs. See https://github.com/devanych/psr-http-benchmark (higher is better)

Installation

composer require nyholm/psr7

If you are using Symfony Flex then you get all message factories registered as services.

Usage

The PSR-7 objects do not contain any other public methods than those defined in the PSR-7 specification.

Create objects

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');

Sending a request

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);

Create server requests

The 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 \Nyholm\Psr7Server\ServerRequestCreator(
    $psr17Factory, // ServerRequestFactory
    $psr17Factory, // UriFactory
    $psr17Factory, // UploadedFileFactory
    $psr17Factory  // StreamFactory
);

$serverRequest = $creator->fromGlobals();

Emitting a response

composer require laminas/laminas-httphandlerrunner
$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory();

$responseBody = $psr17Factory->createStream('Hello world');
$response = $psr17Factory->createResponse(200)->withBody($responseBody);
(new \Laminas\HttpHandlerRunner\Emitter\SapiEmitter())->emit($response);

Our goal

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.

More Repositories

1

NSA

Writing test code should be simple
PHP
221
star
2

psr7-server

Helper classes to use any PSR7 implementation as your main request and response
PHP
84
star
3

dsn

A powerful DSN parser.
PHP
82
star
4

SuperSlim

A small and super quick framework for your microservices
PHP
36
star
5

effective-interest-rate

Calculate effective interest, XIRR or effective APR.
PHP
21
star
6

next-faker

19
star
7

append_query_string

Append a query string to a URL
PHP
18
star
8

symfony-messenger-recorder

An implementation for MessageRecorder for Symfony messenger
PHP
15
star
9

sunflower

The best kernel for simple apps
PHP
14
star
10

workshop-state-machines

14
star
11

workshop-symfony-internals

11
star
12

roave-bc-check-docker

Roave BC Check with Docker
Dockerfile
10
star
13

effective-interest-rate-js

Calculate effective interest, XIRR or effective APR.
JavaScript
9
star
14

symfony-4-internals-presentaion

This is the source code for the Symfony 4 internals
PHP
7
star
15

symfony-runtime

Temporary repository for symfony/symfony#36652
PHP
6
star
16

sfhackday.com

PHP
5
star
17

message-component-demo

PHP
5
star
18

http-client

A super lightweight PSR-7 Http client
PHP
5
star
19

small-symfony-project

This is just a dummy project that loads a bunch of files and runs hello world
PHP
4
star
20

Wordpress-Email-Subscription

The plugin gives your visitors the opportunity to subscribe to future posts by email.
PHP
4
star
21

git-reviewer

Find a list of reviewers for your pull request
PHP
3
star
22

clean-aws-lambda-code-storage

Small application to fix CodeStorageExceededException
PHP
2
star
23

bref-runtime-demo

PHP
2
star
24

php-cs-fixer-Jenkins-plugin

A Jenkins plugin for php-cs-fixer
Java
1
star
25

workshop-logging-with-wordpress

PHP
1
star
26

sf-bref-session-issue

PHP
1
star
27

sf-issue-42303

PHP
1
star
28

sf-issue-40600

PHP
1
star
29

serverless-issue-8772

JavaScript
1
star
30

phpstorm-test-code

PHP
1
star
31

symfony-bootstrap-form

Create a test page for symfony boostrap form.
PHP
1
star
32

noop

No-operation
PHP
1
star
33

Chrome-HTML5-form-validation-remover

This little plugin disables the HTML form validation
JavaScript
1
star
34

bref-issue-output-started

PHP
1
star
35

matlab-why

A port of Matlab's why function
PHP
1
star