# @fastify/accept-negotiator

> a negotiator for the accept-headers

Latest version **2.1.0** (published 2026-08-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @fastify/accept-negotiator
pnpm add @fastify/accept-negotiator
yarn add @fastify/accept-negotiator
bun add @fastify/accept-negotiator
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2026-08-08 |
| First published | 2022-06-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Aras Abbasi |
| Maintainers | jsumners, eomm, climba03003, gurgunday, fdawgs, ivan-tymoshenko |
| Keywords | encoding, negotiator, accept-encoding, accept, http, header |

## Links

- npm: https://www.npmjs.com/package/@fastify/accept-negotiator
- Repository: https://github.com/fastify/accept-negotiator
- Homepage: https://github.com/fastify/accept-negotiator#readme
- Issues: https://github.com/fastify/accept-negotiator/issues
- Funding: https://github.com/sponsors/fastify
- npm.io page: https://npm.io/package/@fastify/accept-negotiator

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 2.1.0 (latest) — 2026-08-08
- 2.0.0 (next) — 2024-09-03
- 2.0.1 — 2025-01-02
- 2.0.0-pre.fv5.1 — 2024-07-05
- 1.1.0 — 2022-12-04
- 1.0.0 — 2022-06-26

## README

# @fastify/accept-negotiator


[![CI](https://github.com/fastify/accept-negotiator/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/accept-negotiator/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/accept-negotiator.svg?style=flat)](https://www.npmjs.com/package/@fastify/accept-negotiator)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

A negotiator for accept-* headers.

### Install
```
npm i @fastify/accept-negotiator
```

### Usage

The module exports a function that you can use for negotiating an accept-* header such as [`accept-encoding`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Accept-Encoding). It takes 2 parameters:

```
negotiate(header, supportedValues)
```

- `header` (`string`, required) - The accept-header, e.g. accept-encoding
- `supportedValues` (`string[]`, required) - The values, which are supported

```js
const negotiate = require('@fastify/accept-negotiator').negotiate
const encoding = negotiate('gzip, deflate, br', ['br'])
console.log(encoding) // 'br*
```

The module also exports a class that you can use for negotiating an accept-* header, and use caching for better performance.


```
Negotiate(supportedValues)
```

- `supportedValues` (`string[]`, required) - The values, which are supported
- `cache` (`{ set: Function; get: Function; has: Function }`, optional) - A Cache-Store, e.g. ES6-Map or mnemonist LRUCache

```js
const Negotiator = require('@fastify/accept-negotiator').Negotiator
const encodingNegotiator = new Negotiator({ supportedValues: ['br'], cache: new Map() })

const encoding = encodingNegotiator.negotiate('gzip, deflate, br')
console.log(encoding) // 'br*
```

## License

Licensed under [MIT](./LICENSE).

---
_Source: https://npm.io/package/@fastify/accept-negotiator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
