@swvl/express-versioned-route
v2.2.4
Published
Simple express.js 4.x extension, to add support for versioned routes.
Downloads
5
Readme
Express-Versioned-Route
Simple express.js 4.x extension, to add support for versioned routes.
Highlights
- Versioning the same route
- Loading time validation
- Custom middlewares for each version
- Built-in soft deprecation policy
- Case insensitive name matching
- Minimal overhead ( less than 0.15ms/request )
- Dynamic routing based on client headers
- Client can choose specific version using
accept-version
header
Install
npm install @swvl/express-versioned-route
Usage
const searchVersionDef = versionsDef()({
versions: {
simpleSearch: ['2020-Q1', searchMW1, searchMW2, searchHandlerV1],
dynamicSearch: [dynamicSearchMW1, dynamicSearchMW2, searchHandlerV2, 'default'],
superSearch: [searchHandlerV3],
deepSearch: [searchHandlerV4],
},
Android: [
[400, 'simpleSearch'],
[450, 'dynamicSearch'],
[500, 'superSearch'],
],
iOS: [
[400, 'simpleSearch'],
[460, 'dynamicSearch'],
],
});
app.get('/search', mw1, mw2, searchVersionDef);
Expected user headers
- device-os & build-number
- accept-version
Options
Global options can be passed as 1st parameter for versionsDef function, or configured as part of versionsDef specs
Example
const searchVersionDef = versionsDef(globalOptions)({
versions: {
...
}
...,
options: {
...
}
});