PHPackages                             cn-tools/negotiation-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. cn-tools/negotiation-middleware

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

cn-tools/negotiation-middleware
===============================

Content negotiation middleware for Slim v4 / PSR-15.

01PHP

Since Nov 12Pushed 6mo agoCompare

[ Source](https://github.com/cn-tools/negotiation-middleware)[ Packagist](https://packagist.org/packages/cn-tools/negotiation-middleware)[ RSS](/packages/cn-tools-negotiation-middleware/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

NegotiationMiddleware
=====================

[](#negotiationmiddleware)

**ℹ️ WARNING:**

This repo is based on [rszrama/negotiation-middleware](https://github.com/rszrama/negotiation-middleware).
I try/made a porting to slim v4 only and add some little test cases.

This repo is in DEV-Mode! PR are welcome!

The content of this README is not actuall! Be aware to check the code by yourself!

NegotiationMiddleware provides content negotiation middleware for PHP applications using a middleware signature that requires a request object, a response object, and the next callable in the middleware stack.

This library depends on [willdurand/negotiation](https://github.com/willdurand/Negotiation) for content negotiation. It allows you to add negotiation to a middleware stack that:

1. Identifies and matches against a list of acceptable media types.
2. Supplies a default media type in the absence of an Accept request header.
3. Enriches the request object with the negotiated media type.

If the negotiator cannot determine which media type to use in response to the request, it will return a response with a 406 Not Acceptable status.

Installation
------------

[](#installation)

Use [Composer](https://getcomposer.org/) to install [NegotiationMiddleware](https://packagist.org/packages/cn-tools/negotiation-middleware):

```
$ composer require cn-tools/negotiation-middleware
```

This will install the library and its dependencies. NegotiationMiddleware requires PHP 8.0 or newer.

Usage - POSSIBLY WRONG
----------------------

[](#usage---possibly-wrong)

Add an instance of NegotiationMiddleware\\Negotiator to an application or route level middleware stack, passing two arguments to the constructor: an array of acceptable media types to be matched against and a boolean indicating whether or not the middleware should simply match the first acceptable media type in the absence of an Accept header in the request.

Example from Slim 4.x:

```
