express-api-version
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

express-api-version

npm package Build Status Downloads Code Coverage

The module adds convenient versioning to your project. You can specify versions anywhere of request (path, query, headers). Use semver format. Before each handler, put a middleware with a version check, if it does not satisfies, there will be a continue to the next handler.

Install

npm install express-api-version

Usage

Add versionParser middleware and specialize the path to version relative to the Request.

import express from 'express'
import { versionParser, versionSatisfies } from 'express-api-version'

const app = express()

app.use(versionParser('query.v')) // Request.query.v

// curl -s localhost:5000/test?v=1.1.2
app.get('/test', versionSatisfies('1.0.0 - 1.2.3'), (req, res) => {
  return res.send('1')
})

// curl -s localhost:5000/test?v=0.3.0
app.get('/test', versionSatisfies('<1.0.0'), (req, res) => {
  return res.send('0')
})

app.listen(5000)

For using x-api-version header:

app.use(versionParser('headers.x-api-version'))

Package Sidebar

Install

npm i express-api-version

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

7.82 kB

Total Files

4

Last publish

Collaborators

  • soprachevak