
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
express-route-versioning
Advanced tools
Express middleware that re-routes requests based on HTTP header value
#express-route-versioning A Connect style middleware to re-direct the execution flow into multiple branches based on HTTP header values. Tested and used for REST API versioning with Express routes but other applications might be suiting.
##Features
Customize the extraction of the version via version.use(options)
for:
header
, i.e. version.use({header: 'Accept-Version'})
grab
, i.e. version.use({grab: /vnd.my.company.()})
Customize the HTTP status code for a failed re-routing using the error
, i.e. version.use({error: 404})
##Example
Re-route based on version in HTTP header Accept: vnd.mycompany.com+json; version=1
.
var express = require('express');
version = require('express-version-reroute');
version.use({
'header': 'accept',
'grab': /vnd.mycompany.com\+json; version=(\d+)(,|$)/,
'error': 406,
});
var router = express.Router()
.all('/ping',
version.reroute({
1: function(req, res, next) { res.json('pong'); },
2: function(req, res, next) { res.status(200).end(); },
})
);
express().use(router).listen(5000, function() {});
cURL examples that give different behavior based on version.
ā ~ curl -i -X GET 'http://127.0.0.1:5000/ping' -H 'Accept: vnd.mycompany.com+json; version=2'
HTTP/1.1 200 OK
X-Powered-By: Express
Date: Wed, 05 Nov 2014 10:09:50 GMT
Connection: keep-alive
Transfer-Encoding: chunked
ā ~ curl -i -X GET 'http://127.0.0.1:5000/ping' -H 'Accept: vnd.mycompany.com+json; version=1'
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 6
ETag: W/"6-dca458aa"
Date: Wed, 05 Nov 2014 10:09:56 GMT
Connection: keep-alive
"pong"%
ā ~ curl -i -X GET 'http://127.0.0.1:5000/ping' -H 'Accept: vnd.mycompany.com+json; version=0'
HTTP/1.1 406 Not Acceptable
X-Powered-By: Express
Date: Wed, 05 Nov 2014 10:09:58 GMT
Connection: keep-alive
Transfer-Encoding: chunked
npm install
npm test
FAQs
Express middleware that re-routes requests based on HTTP header value
The npm package express-route-versioning receives a total of 55 weekly downloads. As such, express-route-versioning popularity was classified as not popular.
We found that express-route-versioning demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.Ā It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.