@fastify/accept-negotiator
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

@fastify/accept-negotiator

CI NPM version js-standard-style

A negotiator for the accept-headers

Install

npm i @fastify/accept-negotiator

Usage

The module exports a function that you can use for negotiating an accept-header, e.g. 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
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, e.g. accept-encoding, 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
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.

Package Sidebar

Install

npm i @fastify/accept-negotiator

Weekly Downloads

748,198

Version

1.1.0

License

MIT

Unpacked Size

8.2 kB

Total Files

5

Last publish

Collaborators

  • gurgunday
  • metcoder95
  • galvez
  • simenb
  • coopflow
  • simoneb
  • rafaelgss
  • starptech
  • delvedor
  • matteo.collina
  • allevo
  • jsumners
  • zekth
  • eomm
  • fox1t
  • airhorns
  • kibertoad
  • climba03003