PHPackages                             accruio/response-middleware - 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. accruio/response-middleware

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

accruio/response-middleware
===========================

Relay-compatible response middleware.

1.0.0(10y ago)134MITPHP

Since Jul 23Pushed 10y ago2 watchersCompare

[ Source](https://github.com/Accruio/ResponseMiddleware)[ Packagist](https://packagist.org/packages/accruio/response-middleware)[ Docs](https://github.com/relayphp/Relay.Middleware)[ RSS](/packages/accruio-response-middleware/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelogDependencies (2)Versions (4)Used By (0)

Relay Response Middleware
=========================

[](#relay-response-middleware)

[![Build Status](https://camo.githubusercontent.com/382d5ac9a51155a01a3c38ad24a8af1f78d790610ac443ace5e87126e976a9f3/68747470733a2f2f7472617669732d63692e6f72672f4163637275696f2f526573706f6e73654d6964646c65776172652e7376673f6272616e63683d312e78)](https://travis-ci.org/Accruio/ResponseMiddleware)[![Latest Stable Version](https://camo.githubusercontent.com/6c88b5546e62043741fb923123b9852c87717ab41844d037a6c22302f7e271cc/68747470733a2f2f706f7365722e707567782e6f72672f6163637275696f2f726573706f6e73652d6d6964646c65776172652f762f737461626c65)](https://packagist.org/packages/accruio/response-middleware)[![Total Downloads](https://camo.githubusercontent.com/4a592b808b100905273f189b69fdf4ce8f85fcc61aa3529dca38805b1724ea84/68747470733a2f2f706f7365722e707567782e6f72672f6163637275696f2f726573706f6e73652d6d6964646c65776172652f646f776e6c6f616473)](https://packagist.org/packages/accruio/response-middleware)[![Latest Unstable Version](https://camo.githubusercontent.com/6f36517114a2851ea8989b0ae1907561bdaafaf4d0b2c460f70d0d23b16ae59d/68747470733a2f2f706f7365722e707567782e6f72672f6163637275696f2f726573706f6e73652d6d6964646c65776172652f762f756e737461626c65)](https://packagist.org/packages/accruio/response-middleware)[![License](https://camo.githubusercontent.com/e9de72c64e5df09f891dccf9ef1950b4b92da80ab36378a4ecc3b5dd1a85d929/68747470733a2f2f706f7365722e707567782e6f72672f6163637275696f2f726573706f6e73652d6d6964646c65776172652f6c6963656e7365)](https://packagist.org/packages/accruio/response-middleware)

This package include the following Relay-compatible response middleware:

- *ResponseSender* to send a PSR-7 response
- *ExceptionHandler* to handle exceptions from subsequent middleware
- *FormContentHandler* to deserialize the URL-encoded payload of a PSR-7 request
- *JsonContentHandler* to deserialize the JSON payload of a PSR-7 request
- *JsonDecoder* to deserialize the JSON payload of a PSR-7 request (**deprecated**)

This package is installable and PSR-4 autoloadable via Composer as `relay/middleware`.

ResponseSender
--------------

[](#responsesender)

The *ResponseSender* does just what it sounds like: it sends the PSR-7 response object.

The *ResponseSender* does nothing with the `$request` or `$response`, passing them immediately to `$next`. Afterwards, it takes the returned `$response` and sends it using `header()` and `echo`, and returns the sent `$response`.

The *ResponseSender* is intended to go at the top of the Relay queue, so that it is the middleware with the last opportunity to do something with the returned response.

To add the *ResponseSender* to your Relay queue, instantiate it directly ...

```
$queue[] = new \Relay\Middleware\ResponseSender();
```

... or use a `$resolver` of your choice to instantiate it from the `$queue`.

ExceptionHandler
----------------

[](#exceptionhandler)

Similarly, the *ExceptionHandler* does what it sound like: it catches any exceptions that bubble up through the subsequent middleware decorators.

The *ExceptionHandler* does nothing with the `$request` or `$response`, and passes them directly to `$next` inside a `try/catch` block. If no exception bubbles up, it returns the `$response` from `$next`. However, if it catches an exception, it returns an entirely new `$response` object with the exception message and an HTTP 500 status code. It then returns the new `$response` object.

The *ExceptionHandler* is intended to go near the top of the Relay queue, but after the *ResponseSender*, so that the *ResponseSender* can then send the returned `$response`.

To add the *ExceptionHandler* to your queue, instantiate it directly with an empty $response implementation object ...

```
$queue = new \Relay\Middleware\ExceptionHandler(new ResponseImplementation());
```

... or use a `$resolver` of your choice to instantiate it from the `$queue`.

JsonContentHandler
------------------

[](#jsoncontenthandler)

Again, the *JsonContentHandler* does what it sounds like: it deserializes the JSON payload of a PSR-7 request object and makes the parameters available in subsequent middleware decorators.

The *JsonContentHandler* checks the incoming request for a method other than `GET`and for an `application/json` or `application/vnd.api+json` `Content-Type` header. If it finds both of these, it parses the JSON and makes it available as the *parsed body* of the `$request` before passing it and the `$response` to `$next`. If the method is `GET` or the `Content-Type` header defines a different mime type, the *JsonContentHandler* ignores the `$request` and continues the chain.

To add the *JsonContentHandler* to your queue, instantiate it directly...

```
$queue = new \Relay\Middleware\JsonContentHandler();
```

... or use a `$resolver` of your choice to instantiate it from the `$queue`.

To access the decoded parameters in subsequent middleware, use the `getParsedBody()` method of the `$request`

```
$decodedJsonData = $request->getParsedBody();
```

FormContentHandler
------------------

[](#formcontenthandler)

*FormContentHandler* works almost identically to *JsonContentHandler*, but parses payloads of requests that have `application/x-www-form-urlencoded` as the `Content-Type`.

JsonDecoder
-----------

[](#jsondecoder)

**NOTE: This handler has been deprecated in favor of *JsonContentHandler*!**

Again, the *JsonDecoder* does what it sounds like: it deserializes the JSON payload of a PSR-7 request object and makes the parameters available in subsequent middleware decorators.

The *JsonDecoder* checks the incoming request for a method other than `GET` and for an `application/json` `Content-Type` header. If it finds both of these, it decodes the JSON and makes it available as the *parsed body* of the `$request`before passing it and the `$response` to `$next`. If the method is `GET` or the `Content-Type` header does not specify `application/json`, the *JsonDecoder*does nothing with the `$request` and passes it and the `$response` to `$next`.

To add the *JsonDecoder* to your queue, instantiate it directly...

```
$queue = new \Relay\Middleware\JsonDecoder();
```

... or use a `$resolver` of your choice to instantiate it from the `$queue`.

To access the decoded parameters in subsequent middleware, use the `getParsedBody()` method of the `$request`

```
$decodedJsonData = $request->getParsedBody();
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~146 days

Total

3

Last Release

3650d ago

Major Versions

0.1.0 → 1.0.02016-02-22

### Community

Maintainers

![](https://www.gravatar.com/avatar/0385f2ce40d103cf7b260a5412c46aaeb59bb514dfe0ece393d49e868e008481?d=identicon)[accruio](/maintainers/accruio)

---

Top Contributors

[![maanas](https://avatars.githubusercontent.com/u/299412?v=4)](https://github.com/maanas "maanas (7 commits)")[![cgray](https://avatars.githubusercontent.com/u/3750843?v=4)](https://github.com/cgray "cgray (6 commits)")[![rpalladino](https://avatars.githubusercontent.com/u/1429151?v=4)](https://github.com/rpalladino "rpalladino (4 commits)")[![bryanagee](https://avatars.githubusercontent.com/u/290124?v=4)](https://github.com/bryanagee "bryanagee (2 commits)")[![cxj](https://avatars.githubusercontent.com/u/446131?v=4)](https://github.com/cxj "cxj (2 commits)")[![shadowhand](https://avatars.githubusercontent.com/u/38203?v=4)](https://github.com/shadowhand "shadowhand (1 commits)")[![elazar](https://avatars.githubusercontent.com/u/15487?v=4)](https://github.com/elazar "elazar (1 commits)")[![jakejohns](https://avatars.githubusercontent.com/u/174708?v=4)](https://github.com/jakejohns "jakejohns (1 commits)")

### Embed Badge

![Health badge](/badges/accruio-response-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/accruio-response-middleware/health.svg)](https://phpackages.com/packages/accruio-response-middleware)
```

###  Alternatives

[league/uri-interfaces

Common tools for parsing and resolving RFC3987/RFC3986 URI

538204.9M23](/packages/league-uri-interfaces)[shopify/shopify-api

Shopify API Library for PHP

4634.8M16](/packages/shopify-shopify-api)[laudis/neo4j-php-client

Neo4j-PHP-Client is the most advanced PHP Client for Neo4j

184616.9k31](/packages/laudis-neo4j-php-client)[http-interop/response-sender

A function to convert PSR-7 Response to HTTP output

46711.5k40](/packages/http-interop-response-sender)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28483.0k2](/packages/mezzio-mezzio-authentication-oauth2)

PHPackages © 2026

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