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.
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
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);
Must contain a string or an array of strings.