Home

Awesome

http-version Build Status NPM

HTTP API version middleware pluggable with connect/express/rocky. 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

Supported headers are (case insensitive): Version, X-Version, API-Version and X-API-Version

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