PHPackages                             shieldon/psr-http - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. shieldon/psr-http

ActiveLibrary[HTTP &amp; Networking](/categories/http)

shieldon/psr-http
=================

HTTP implementation for PSR standard.

1.2.7(3y ago)1828.3k↓33.3%1[2 issues](https://github.com/terrylinooo/psr-http/issues)4MITPHPPHP &gt;=7.1.0CI failing

Since Jul 4Pushed 3y ago3 watchersCompare

[ Source](https://github.com/terrylinooo/psr-http)[ Packagist](https://packagist.org/packages/shieldon/psr-http)[ Docs](https://github.com/terrylinooo/psr-http)[ RSS](/packages/shieldon-psr-http/feed)WikiDiscussions master Synced yesterday

READMEChangelog (6)Dependencies (5)Versions (7)Used By (4)

PSR 7, 15, 17 Implementation and Examples
=========================================

[](#psr-7-15-17-implementation-and-examples)

[![build](https://github.com/terrylinooo/psr-http/workflows/build/badge.svg)](https://github.com/terrylinooo/psr-http/workflows/build/badge.svg) [![codecov](https://camo.githubusercontent.com/8b2c514af2999501ff9dc7be42add186dd8430eb6f88a05ce9a83f3ab3941abd/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f74657272796c696e6f6f6f2f7073722d687474702e737667)](https://codecov.io/gh/terrylinooo/psr-http) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/37f3d44bf3f00a256787f1538fdd41ba0df55ebb51d0e0a25ed0d2ece081c41b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f74657272796c696e6f6f6f2f7073722d687474702f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/terrylinooo/psr-http/?branch=master) [![License: MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](https://opensource.org/licenses/MIT)

This library is a PSR HTTP implementation created for [Shieldon firewall 2](https://github.com/terrylinooo/shieldon) , following up the PSR (PHP Standard Recommendation) documents by one hundred percent.

- **PSR-7** (HTTP Message Interfaces)
- **PSR-15** (HTTP Server Request Handlers)
- **PSR-17** (HTTP Factories)

### Test Status

[](#test-status)

Shiledon PSR-HTTP library is strictly tested by unit tests contain almost all conditions that might be happened, if you find any bug or something that can improve this library, please let me know.

Test suiteStatusRepository built-in tests[![Build Status](https://camo.githubusercontent.com/a6831c721208dba5d32a8b619d8ab084f3aaac3a7a53ec31aa8202b6f1aa0db1/68747470733a2f2f7472617669732d63692e6f72672f74657272796c696e6f6f6f2f7073722d687474702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/terrylinooo/psr-http)[PSR-7 integration tests](https://github.com/terrylinooo/psr7-integration-tests)[![Build Status](https://camo.githubusercontent.com/b3c20ab7a7f666ff08fe4288bf05defb536fb3488ddcfbcb95159a63773110f4/68747470733a2f2f7472617669732d63692e6f72672f74657272796c696e6f6f6f2f707372372d696e746567726174696f6e2d74657374732e7376673f6272616e63683d736869656c646f6e2d7073722d68747470)](https://travis-ci.org/terrylinooo/psr7-integration-tests)You can use it on any framework which is compatible with those PSRs.

Install
-------

[](#install)

```
composer require shieldon/psr-http
```

Test
----

[](#test)

```
composer install
composer test
```

Quick Start
-----------

[](#quick-start)

The simplest way to start implementing PSR-7 on your PHP applications, let's check out the examples below.

*Create a server request.*

```
$serverRequest = ServerRequestFactory::fromGlobal();
```

*Create a request.*

```
$request = RequestFactory::fromNew();
```

*Create a server response*

```
$response = ResponseFactory::fromNew();
```

*Create a URI.*

```
// Create a URI contains visitor's information.

/**
 *  Assume a visior is viewing your website page,
 *  for example, https://yoursite/en/post1.html
 */
$uri = UriFactory::fromGlobal();

echo $uri->getPath();
// Outputs: /en/post1.html

// Create a URI just a new instance.
$uri = UriFactory::fromNew();

echo $uri->getPath();
// Outputs:
```

*Create a stream instance.*

```
// Create a stream just a new instance.
$stream = StreamFactory::fromNew();
```

*Create an array with UploadedFile structure.*

```
// Let's see the following example,
// assume we have a superglobal $_FILES looks like this.
$_FILES = [
    'foo' => [
        'name' => 'example1.jpg',
        'type' => 'image/jpeg',
        'tmp_name' => '/tmp/php200A.tmp',
        'error' => 0,
        'size' => 100000,
    ]
];

$uploadFileArr = UploadedFileFactory::fromGlobal();

echo $uploadFileArr['foo']->getClientFilename();
// Outputs: example1.jpg
```

Table of Contents
-----------------

[](#table-of-contents)

- ### **PSR-17**: *HTTP Factories*

    [](#psr-17-http-factories)

    - #### [RequestFactory](https://github.com/terrylinooo/psr-http/wiki/PSR-17:-RequestFactory-Example)

        [](#requestfactory)

        - [createRequest](https://github.com/terrylinooo/psr-http/wiki/RequestFactory:-createRequest-Example)
        - [::fromNew](https://github.com/terrylinooo/psr-http/wiki/RequestFactory:-fromNew-Example) `(Non-PSR)`
    - #### [ServerRequestFactory](https://github.com/terrylinooo/psr-http/wiki/PSR-17:-ServerRequestFactory-Example)

        [](#serverrequestfactory)

        - [createServerRequest](https://github.com/terrylinooo/psr-http/wiki/ServerRequestFactory:-createServerRequest-Example)
        - [::fromGlobal](https://github.com/terrylinooo/psr-http/wiki/ServerRequestFactory:-fromGlobal-Example) `(Non-PSR)`
    - #### [ResponseFactory](https://github.com/terrylinooo/psr-http/wiki/PSR-17:-ResponseFactory-Example)

        [](#responsefactory)

        - [createResponse](https://github.com/terrylinooo/psr-http/wiki/ResponseFactory:-createResponse-Example)
        - [::fromNew](https://github.com/terrylinooo/psr-http/wiki/ResponseFactory:-fromNew-Example) `(Non-PSR)`
    - #### [StreamFactory](https://github.com/terrylinooo/psr-http/wiki/PSR-17:-StreamFactory-Example)

        [](#streamfactory)

        - [createStream](https://github.com/terrylinooo/psr-http/wiki/StreamFactory:-createStream-Example)
        - [createStreamFromFile](https://github.com/terrylinooo/psr-http/wiki/StreamFactory:-createStreamFromFile-Example)
        - [createStreamFromResource](https://github.com/terrylinooo/psr-http/wiki/StreamFactory:-createStreamFromResource-Example)
        - [::fromNew](https://github.com/terrylinooo/psr-http/wiki/UploadedFileFactory:-fromNew-Example) `(Non-PSR)`
    - #### [UploadedFileFactory](https://github.com/terrylinooo/psr-http/wiki/PSR-17:-UploadedFileFactory-Example)

        [](#uploadedfilefactory)

        - [createUploadedFile](https://github.com/terrylinooo/psr-http/wiki/UploadedFileFactory:-createUploadedFile-Example)
        - [::fromGlobal](https://github.com/terrylinooo/psr-http/wiki/UploadedFileFactory:-fromGlobal-Example) `(Non-PSR)`
    - #### [UriFactory](https://github.com/terrylinooo/psr-http/wiki/PSR-17:-UriFactory-Example)

        [](#urifactory)

        - [createUri](https://github.com/terrylinooo/psr-http/wiki/UriFactory:-createUri-Example)
        - [::fromGlobal](https://github.com/terrylinooo/psr-http/wiki/UriFactory:-fromGlobal-Example) `(Non-PSR)`
        - [::fromNew](https://github.com/terrylinooo/psr-http/wiki/UriFactory:-fromNew-Example) `(Non-PSR)`
- ### **PSR-7**: *HTTP Message Interfaces*

    [](#psr-7-http-message-interfaces)

    - #### [Message](https://github.com/terrylinooo/psr-http/wiki/PSR-7:-Message-Example)

        [](#message)

        - [getProtocolVersion](https://github.com/terrylinooo/psr-http/wiki/Message:-getProtocolVersion-Example)
        - [withProtocolVersion](https://github.com/terrylinooo/psr-http/wiki/Message:-withProtocolVersion-Example)
        - [setHeaders](https://github.com/terrylinooo/psr-http/wiki/Message:-setHeaders-Example) `(Non-PSR)`
        - [getHeaders](https://github.com/terrylinooo/psr-http/wiki/Message:-getHeaders-Example)
        - [hasHeader](https://github.com/terrylinooo/psr-http/wiki/Message:-hasHeader-Example)
        - [getHeader](https://github.com/terrylinooo/psr-http/wiki/Message:-getHeader-Example)
        - [getHeaderLine](https://github.com/terrylinooo/psr-http/wiki/Message:-getHeaderLine-Example)
        - [withHeader](https://github.com/terrylinooo/psr-http/wiki/Message:-withHeader-Example)
        - [withAddedHeader](https://github.com/terrylinooo/psr-http/wiki/Message:-withAddedHeader-Example)
        - [withoutHeader](https://github.com/terrylinooo/psr-http/wiki/Message:-withoutHeader-Example)
        - [getBody](https://github.com/terrylinooo/psr-http/wiki/Message:-getBody-Example)
        - [withBody](https://github.com/terrylinooo/psr-http/wiki/Message:-withBody-Example)
    - #### [Request](https://github.com/terrylinooo/psr-http/wiki/PSR-7:-Request-Example) *(externds Message)*

        [](#request-externds-message)

        - [\_\_construct](https://github.com/terrylinooo/psr-http/wiki/Request:-__construct-Example) `(Non-PSR)`
        - [getRequestTarget](https://github.com/terrylinooo/psr-http/wiki/Request:-getRequestTarget-Example)
        - [withRequestTarget](https://github.com/terrylinooo/psr-http/wiki/Request:-withRequestTarget-Example)
        - [getMethod](https://github.com/terrylinooo/psr-http/wiki/Request:-getMethod-Example)
        - [withMethod](https://github.com/terrylinooo/psr-http/wiki/Request:-withMethod-Example)
        - [getUri](https://github.com/terrylinooo/psr-http/wiki/Request:-getUri-Example)
        - [withUri](https://github.com/terrylinooo/psr-http/wiki/Request:-withUri-Example)
    - #### [ServerRequest](https://github.com/terrylinooo/psr-http/wiki/PSR-7:-ServerRequest-Example) *(externds Request)*

        [](#serverrequest-externds-request)

        - [\_\_construct](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-__construct-Example) `(Non-PSR)`
        - [getServerParams](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-getServerParams-Example)
        - [getCookieParams](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-getCookieParams-Example)
        - [withCookieParams](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-withCookieParams-Example)
        - [getQueryParams](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-getQueryParams-Example)
        - [withQueryParams](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-withQueryParams-Example)
        - [getUploadedFiles](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-getUploadedFiles-Example)
        - [withUploadedFiles](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-withUploadedFiles-Example)
        - [getParsedBody](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-getParsedBody-Example) (See explanation below)
        - [withParsedBody](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-withParsedBody-Example)
        - [getAttributes](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-getAttributes-Example)
        - [getAttribute](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-getAttribute-Example)
        - [withAttribute](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-withAttribute-Example)
        - [withoutAttribute](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-withoutAttribute-Example)
    - #### [Response](https://github.com/terrylinooo/psr-http/wiki/PSR-7:-Response-Example) *(externds Message)*

        [](#response-externds-message)

        - [\_\_construct](https://github.com/terrylinooo/psr-http/wiki/Request:-__construct-Example) `(Non-PSR)`
        - [getStatusCode](https://github.com/terrylinooo/psr-http/wiki/Request:-getStatusCode-Example)
        - [withStatus](https://github.com/terrylinooo/psr-http/wiki/Request:-withStatus-Example)
        - [getReasonPhrase](https://github.com/terrylinooo/psr-http/wiki/Request:-getReasonPhrase-Example)
    - #### [Stream](https://github.com/terrylinooo/psr-http/wiki/PSR-7:-Stream-Example)

        [](#stream)

        - [\_\_construct](https://github.com/terrylinooo/psr-http/wiki/Stream:-__construct-Example) `(Non-PSR)`
        - [isWritable](https://github.com/terrylinooo/psr-http/wiki/Stream:-isWritable-Example)
        - [isReadable](https://github.com/terrylinooo/psr-http/wiki/Stream:-isReadable-Example)
        - [isSeekable](https://github.com/terrylinooo/psr-http/wiki/Stream:-isSeekable-Example)
        - [close](https://github.com/terrylinooo/psr-http/wiki/Stream:-close-Example)
        - [detach](https://github.com/terrylinooo/psr-http/wiki/Stream:-detach-Example)
        - [getSize](https://github.com/terrylinooo/psr-http/wiki/Stream:-getSize-Example)
        - [tell](https://github.com/terrylinooo/psr-http/wiki/Stream:-tell-Example)
        - [eof](https://github.com/terrylinooo/psr-http/wiki/Stream:-eof-Example)
        - [seek](https://github.com/terrylinooo/psr-http/wiki/Stream:-seek-Example)
        - [rewind](https://github.com/terrylinooo/psr-http/wiki/Stream:-rewind-Example)
        - [write](https://github.com/terrylinooo/psr-http/wiki/Stream:-write-Example)
        - [read](https://github.com/terrylinooo/psr-http/wiki/Stream:-read-Example)
        - [getContents](https://github.com/terrylinooo/psr-http/wiki/Stream:-getContents-Example)
        - [getMetadata](https://github.com/terrylinooo/psr-http/wiki/Stream:-getMetadata-Example)
        - [\_\_toString](https://github.com/terrylinooo/psr-http/wiki/Stream:-__toString-Example)
    - #### [UploadedFile](https://github.com/terrylinooo/psr-http/wiki/PSR-7:-UploadedFile-Example)

        [](#uploadedfile)

        - [\_\_construct](https://github.com/terrylinooo/psr-http/wiki/UploadedFile:-__construct-Example) `(Non-PSR)`
        - [getStream](https://github.com/terrylinooo/psr-http/wiki/UploadedFile:-getStream-Example)
        - [moveTo](https://github.com/terrylinooo/psr-http/wiki/UploadedFile:-moveTo-Example)
        - [getSize](https://github.com/terrylinooo/psr-http/wiki/UploadedFile:-getSize-Example)
        - [getError](https://github.com/terrylinooo/psr-http/wiki/UploadedFile:-getError-Example)
        - [getClientFilename](https://github.com/terrylinooo/psr-http/wiki/UploadedFile:-getClientFilename-Example)
        - [getClientMediaType](https://github.com/terrylinooo/psr-http/wiki/UploadedFile:-getClientMediaType-Example)
        - [getErrorMessage](https://github.com/terrylinooo/psr-http/wiki/UploadedFile:-getErrorMessage-Example) `(Non-PSR)`
    - #### [Uri](https://github.com/terrylinooo/psr-http/wiki/PSR-7:-Uri-Example)

        [](#uri)

        - [\_\_construct](https://github.com/terrylinooo/psr-http/wiki/Uri:-__construct-Example) `(Non-PSR)`
        - [getScheme](https://github.com/terrylinooo/psr-http/wiki/Uri:-getScheme-Example)
        - [getAuthority](https://github.com/terrylinooo/psr-http/wiki/Uri:-getAuthority-Example)
        - [getUserInfo](https://github.com/terrylinooo/psr-http/wiki/Uri:-getUserInfo-Example)
        - [getHost](https://github.com/terrylinooo/psr-http/wiki/Uri:-getHost-Example)
        - [getPort](https://github.com/terrylinooo/psr-http/wiki/Uri:-getPort-Example)
        - [getPath](https://github.com/terrylinooo/psr-http/wiki/Uri:-getPath-Example)
        - [getQuery](https://github.com/terrylinooo/psr-http/wiki/Uri:-getQuery-Example)
        - [getFragment](https://github.com/terrylinooo/psr-http/wiki/Uri:-getFragment-Example)
        - [withScheme](https://github.com/terrylinooo/psr-http/wiki/Uri:-withScheme-Example)
        - [withUserInfo](https://github.com/terrylinooo/psr-http/wiki/Uri:-withUserInfo-Example)
        - [withHost](https://github.com/terrylinooo/psr-http/wiki/Uri:-withHost-Example)
        - [withPort](https://github.com/terrylinooo/psr-http/wiki/Uri:-withPort-Example)
        - [withPath](https://github.com/terrylinooo/psr-http/wiki/Uri:-withPath-Example)
        - [withQuery](https://github.com/terrylinooo/psr-http/wiki/Uri:-withQuery-Example)
        - [withFragment](https://github.com/terrylinooo/psr-http/wiki/Uri:-withFragment-Example)
        - [\_\_toString](https://github.com/terrylinooo/psr-http/wiki/Uri:-__toString-Example)
- ### **PSR-15**: *HTTP Server Request Handlers*

    [](#psr-15-http-server-request-handlers)

    - #### [RequestHandler](https://github.com/terrylinooo/psr-http/wiki/PSR-15:-RequestHandler-Example)

        [](#requesthandler)

        - [\_\_construct](https://github.com/terrylinooo/psr-http/wiki/RequestHandler:-__construct-Example) `(Non-PSR)`
        - [add](https://github.com/terrylinooo/psr-http/wiki/RequestHandler:-add-Example)
        - [handle](https://github.com/terrylinooo/psr-http/wiki/RequestHandler:-handle-Example)
    - #### [Middleware](https://github.com/terrylinooo/psr-http/wiki/PSR-15:-Middleware-Example)

        [](#middleware)

        - [process](https://github.com/terrylinooo/psr-http/wiki/Middleware:-process-Example)

If you are looking for combined examples, see [unit testing](https://github.com/terrylinooo/psr-http/tree/master/tests).

### The Behavior of Handling Request Body

[](#the-behavior-of-handling-request-body)

Shieldon PSR-HTTP is ready for RESTful, the following content explains how PRS-HTTP deals with the request body.

The `getParsedBody` method will return:

- **(A)** An array of the superglobal *$\_POST* if the request request method is `POST` and the Content-Type is one of the following types:

    - `multipart/form-data`
    - `application/x-www-form-urlencode`
- **(B)** A JSON object if the request fit to the following conditions.

    - The request Content-Type is `application/json`
    - The request body is a valid *JSON-formatted* string.
    - The request method is not `GET`.
- **(C)** An array parsed from HTTP build query:

    - The condition is neither A or B.
    - The request method is not `GET`.
- **(D)** `null` if the condition is none of above.

#### Summary

[](#summary)

ConditionMethodContent-typeParsed-bodyAPOSTmultipart/form-data
application/x-www-form-urlencodearrayBALL excepts GETapplication/jsonobjectCALL excepts GETAll excepts A or BarrayD--nullHope this helps.

---

Author
------

[](#author)

Shieldon PSR HTTP library is brought to you by [Terry L.](https://terryl.in) from Taiwan.

License
-------

[](#license)

MIT

References
----------

[](#references)

- [PSR-7](https://www.php-fig.org/psr/psr-7/) (HTTP Message Interfaces)
- [PSR-15](https://www.php-fig.org/psr/psr-15/) (HTTP Server Request Handlers)
- [PSR-17](https://www.php-fig.org/psr/psr-17/) (HTTP Factories)

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~213 days

Recently: every ~264 days

Total

6

Last Release

1123d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fca418a834057a4203c6856e316ca4d7c71fa1b9076977e08e5c4d5a9cc9aec6?d=identicon)[terrylinooo](/maintainers/terrylinooo)

---

Top Contributors

[![terrylinooo](https://avatars.githubusercontent.com/u/11989371?v=4)](https://github.com/terrylinooo "terrylinooo (104 commits)")

---

Tags

php-psrpsr-15psr-17psr-7psr-17psr7psr-15php-http

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/shieldon-psr-http/health.svg)

```
[![Health](https://phpackages.com/badges/shieldon-psr-http/health.svg)](https://phpackages.com/packages/shieldon-psr-http)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.1B4.0k](/packages/guzzlehttp-psr7)[cakephp/cakephp

The CakePHP framework

8.9k19.5M1.8k](/packages/cakephp-cakephp)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[typo3/cms-core

TYPO3 CMS Core

3713.2M5.1k](/packages/typo3-cms-core)[sunrise/http-router

A powerful solution as the foundation of your project.

17451.6k10](/packages/sunrise-http-router)[mezzio/mezzio

PSR-15 Middleware Microframework

3923.8M125](/packages/mezzio-mezzio)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
