http-version
v0.1.0
Published
connect/express compatible middleware for HTTP API version switching/routing
Downloads
11
Maintainers
Readme
http-version
connect/express compatible middleware for API version switching/routing. It supports multiple versioning strategies.
Inspired by vhost middleware
Installation
npm install http-version --save
Versioning strategies
Versioning strategies are defined by match order priority
For information about different HTTP APIs version strategies, see http-api-versioning
Header
GET /resource HTTP/1.1
Version: 1.0
Accept version
GET /resource HTTP/1.1
Accept: application/json; version=1.0
Path
GET /v1.0/resource HTTP/1.1
Usage
var express = require('express')
var version = require('http-version')
// Create express apps
var oldAPI = express()
var newAPI = express()
oldAPI.get('/test', testHandler)
newAPI.get('/test', testHandler)
function testHandler(req, res) {
res.end('Processing request from API version: ' + req.version)
}
// Create the main app
var app = express()
// Attach the version middlewares per each app
app.use(version('1.0', oldAPI))
app.use(version('2.0', newAPI))
// Start server
app.listen(3000)
API
version(version, [ strategies ], handle) =>
Function(req, res, next)
version.strategies =>
Array[Function]
License
MIT - Tomas Aparicio