Skip to content

Latest commit

 

History

History
51 lines (35 loc) · 1.74 KB

README.md

File metadata and controls

51 lines (35 loc) · 1.74 KB

express-accepts-exact

Simple express middleware for filtering routes by exact matches of Accepts header.

This is useful for having routes that behave like github's api with experimental features that require one of the accepts be application/vnd.github.pegasus allowing clients to opt into possible breaking changes.

NPM Version NPM Downloads

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install express-accepts-exact --save

Example

Only use this route if accepts header contains application/vnd.mydomain.experimental.

let acceptExact = require("express-accepts-exact");
let acceptExperimental = acceptExact("application/vnd.mydomain.experimental");

router.get("/api/file/:file", acceptExperimental, getFileExperimental);
router.get("/api/file/:file", getFile); // Fallback to non experimental version.

Only use this route if accepts header contains application/vnd.mydomain.custom or plain/text

let acceptExact = require("express-accepts-exact");
app.get("/api/custom-download/:file", acceptExact(["application/vnd.mydomain.custom", "plain/text"]), getFile);

API

acceptExact(paths);

paths

Must contain a string or an array of strings.

License

ISC