Socket
Socket
Sign inDemoInstall

express-semver-routing

Package Overview
Dependencies
1
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    express-semver-routing

Express middleware for request routing based on a provided semver version


Version published
Weekly downloads
2.6K
decreased by-9.75%
Maintainers
1
Install size
102 kB
Created
Weekly downloads
 

Readme

Source

express-semver-routing

An express middleware providing a mechanism for route switching based on a version field of the request. This makes it possible to use semver for express APIs simply by adding a version tag as the first middleware in a route definition.

Usage

const version = require('express-semver-routing')(/* optional arguments /*)

app.get('/api/resource', version('1.x.x'), ...)
app.get('/api/resource', version('2 - 3.1.x'), ...)

Options

Requiring the middleware returns a function that takes optional arguments.

Defaults:
{
  errorConstructor: Error, // (Optional) Constructor used to create errors for invalid versions
  header: 'accept-version' // (Optional) Which header to check for the request version
  getVersion: undefined,   // (Optional) Function which receives the express req as a parameter for custom
                           //            version fields allowing more flexibility than the `header` option
}

Note: getVersion and header cannot be used together (will throw if you do) as it'd be ambiguous where to get the version

Additional Examples

// Using a field from the querystring
const version = require('express-semver-routing')({
  getVersion: (req) => req.query && req.query['api-version']
})
// Using a default version
const version = require('express-semver-routing')({
  getVersion: (req) => req.get('accept-version') || '1.0.0'
})

FAQs

Last updated on 21 Aug 2016

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc