Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

negotiator

Package Overview
Dependencies
Maintainers
3
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

negotiator

HTTP content negotiation

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
44M
increased by12.85%
Maintainers
3
Weekly downloads
 
Created

What is negotiator?

The negotiator npm package is a content negotiation library used to parse and match HTTP headers for various content types. It allows servers to select the best representation of a resource based on the client's capabilities and preferences, as expressed through HTTP headers.

What are negotiator's main functionalities?

Content-Type Negotiation

This feature allows the server to determine the best media type to respond with, based on the client's 'Accept' HTTP header.

const Negotiator = require('negotiator');
const availableMediaTypes = ['text/html', 'application/json'];
const negotiator = new Negotiator(request);
const bestMediaType = negotiator.mediaType(availableMediaTypes);

Language Negotiation

This feature enables the server to select the best language for the response content based on the client's 'Accept-Language' HTTP header.

const Negotiator = require('negotiator');
const availableLanguages = ['en', 'es', 'fr'];
const negotiator = new Negotiator(request);
const bestLanguage = negotiator.language(availableLanguages);

Encoding Negotiation

This feature allows the server to choose the best encoding for the response based on the client's 'Accept-Encoding' HTTP header.

const Negotiator = require('negotiator');
const availableEncodings = ['gzip', 'deflate'];
const negotiator = new Negotiator(request);
const bestEncoding = negotiator.encoding(availableEncodings);

Charset Negotiation

This feature allows the server to determine the best charset for the response content based on the client's 'Accept-Charset' HTTP header.

const Negotiator = require('negotiator');
const availableCharsets = ['utf-8', 'iso-8859-1'];
const negotiator = new Negotiator(request);
const bestCharset = negotiator.charset(availableCharsets);

Other packages similar to negotiator

Keywords

FAQs

Package last updated on 31 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc