{"library":"negotiate","title":"Negotiate.js","description":"JavaScript implementation of the HTTP preemptive content negotiation algorithm as defined in the original HTTP 1.1 draft spec. Stable version 1.0.1, no longer actively developed. Differentiators: implements the original draft negotiation algorithm (not the final RFC), handles media type, language, charset, and encoding negotiation. Suitable for Node.js HTTP servers needing automatic variant selection. Alternative to content-negotiation libraries that follow the final RFC.","language":"javascript","status":"maintenance","last_verified":"Sat Apr 25","install":{"commands":["npm install negotiate"],"cli":null},"imports":["import Negotiate from 'negotiate'","import { choose } from 'negotiate'","const Negotiate = require('negotiate')"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import Negotiate from 'negotiate';\n\nconst variants = [\n  {\n    method: 'GET',\n    type: 'text/html',\n    language: 'en-ca',\n    charset: 'iso-8859-1',\n    encoding: null,\n    quality: 1.0,\n    length: 36741,\n    filename: 'blog.html'\n  },\n  {\n    method: 'GET',\n    type: 'application/atom+xml',\n    language: 'en',\n    charset: 'utf-8',\n    encoding: 'gzip',\n    quality: 0.8,\n    length: 12987,\n    filename: 'blog.atom.gzip'\n  }\n];\n\nconst request = {\n  url: '/blog',\n  method: 'GET',\n  headers: {\n    'accept': 'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',\n    'accept-language': 'en-US,en;q=0.8',\n    'accept-encoding': 'gzip,deflate,sdch',\n    'accept-charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'\n  }\n};\n\nconst responses = Negotiate.choose(variants, request);\nconsole.log(responses[0]);","lang":"typescript","description":"Shows how to define variants and select the best representation for an HTTP request using negotiate.choose().","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}