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

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

gofabian/negotiation-middleware
===============================

PHP negotiation middleware for accept headers of PSR-7 requests. Uses the negotiation library willdurand/negotiation.

v0.1.3(9y ago)1079.7k↓35%3[3 issues](https://github.com/gofabian/negotiation-middleware/issues)MITPHPPHP &gt;=5.4.0

Since Nov 2Pushed 5y ago2 watchersCompare

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

READMEChangelog (2)Dependencies (4)Versions (7)Used By (0)

Negotiation Middleware
======================

[](#negotiation-middleware)

[![Build Status](https://camo.githubusercontent.com/4aec20b6bb956ae91f47127f0f749d7623b4c57916d427ba93420ef6eb4d6074/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f676f66616269616e2f6e65676f74696174696f6e2d6d6964646c65776172652f6275696c643f7374796c653d666c61742d737175617265)](https://github.com/gofabian/negotiation-middleware/actions/workflows/php.yml)[![Coverage Status](https://camo.githubusercontent.com/9cc721959294095355e777fb8edc0fcea28765664b1bdc457918490800866fb2/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f676f66616269616e2f6e65676f74696174696f6e2d6d6964646c65776172652f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562616765)](https://coveralls.io/github/gofabian/negotiation-middleware?branch=master)[![Downloads](https://camo.githubusercontent.com/1eb3477a4fed9787b39d1427563f7ae61237c2178ec109aefa2e143909930e0d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f676f66616269616e2f6e65676f74696174696f6e2d6d6964646c65776172652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gofabian/negotiation-middleware/stats)

The **Negotiation Middleware** is a PHP library that negotiates accept headers of HTTP requests. The middleware chooses the most fitting options by looking at the accepted values of client and server. It supports the headers *accept*, *accept-language*, *accept-encoding* and *accept-charset*.

This library is a [middleware](http://www.slimframework.com/docs/concepts/middleware.html "Concept of Slim middleware") for the [Slim framework 3](http://www.slimframework.com/ "Slim - a PHP micro framework") but may be used for any PHP code that uses HTTP messages conform to [PSR-7](http://www.php-fig.org/psr/psr-7/ "PSR-7 - HTTP message interfaces"). The Negotiation Middleware is based on the [library from William Durand](https://github.com/willdurand/Negotiation "Negotiation library by William Durand").

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

[](#installation)

The recommended way to install the Negotiation Middleware is using [Composer](https://getcomposer.org/ "Composer - Dependency Manager for PHP"):

```
$ composer require gofabian/negotiation-middleware
```

Composer fetches all dependencies automatically. The Negotiation Middleware uses common standards and tries to reduce the number of required packages follwing the [KISS principle](https://en.wikipedia.org/wiki/KISS_principle "Keep it simple, stupid"):

- PHP 7.3+
- PSR-7
- willdurand/negotiation 3.x
- recommended: slim/slim 3.x

Usage
-----

[](#usage)

The first example describes how to use the Slim framework in combination with the Negotiation Middleware. The following examples are less detailed and bring specific aspects into focus.

### Slim and the Negotiation Middleware

[](#slim-and-the-negotiation-middleware)

The most common way is to negotiate the media type. In this example the server accepts the media types `text/html` and `application/json`:

```
