https://github.com/h2non/http-version
HTTP API version matching strategies as middleware for connect/express/rocky
https://github.com/h2non/http-version
Last synced: 5 months ago
JSON representation
HTTP API version matching strategies as middleware for connect/express/rocky
- Host: GitHub
- URL: https://github.com/h2non/http-version
- Owner: h2non
- License: mit
- Created: 2015-06-27T21:52:54.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-08-20T11:45:51.000Z (almost 10 years ago)
- Last Synced: 2024-10-18T11:25:16.450Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 148 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# http-version [](https://travis-ci.org/h2non/http-version) [](https://www.npmjs.org/package/http-version)
HTTP API version middleware pluggable with [connect](https://github.com/senchalabs/connect)/[express](https://github.com/strongloop/express)/[rocky](https://github.com/h2non/rocky). Supports multiple [versioning strategies](#versioning-strategies).
Inspired by [vhost](https://github.com/expressjs/vhost) middleware
## Installation
```bash
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](https://github.com/h2non/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
```js
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