Express API Versioning
Express API versioning is an express middleware that dynamically loads different API versions seamlessly depending on the version number specified in the request url.
What's new in v2
- Version 2 introduces a new way to resolve errors using callback instead of the
npm install express-api-versioning --save
expressis required as a peer dependency.
import expressApiVersioning from 'express-api-versioning';
const expressApiVersioning = require('express-api-versioning');
As of v2, the middleware returns an error object as the first parameter of the callback and has properties
The middleware will throw an error when;
apiPathis not specified
- an express
instanceis not specified and not a function
- the api version cannot be found in the
|1.||101||You must explicitly specify a path to where the APIs reside|
|2.||102||You must explicitly set an instance of express|
|3.||103||Entry point not Found|
|4.||104||No version number found|
|5.||105||An instance of express must be a function but got type
Please use the issues page to report an issue.
Express API Versioning is highly customizable and does not introduce complexities to your application folder structure. It takes a configuration object as parameter.
||Regular expression to get the version number from the request url. It gets the version number from the first group of the regex match.|
|entryPoint||app.js||Entry point for each api version. It exports a function which takes an instance of express as parameter.|
|apiPath||empty string||Absolute path to each api version container/directory. This is usually
|instance||null||An instance of express app which will be passed down to the entry point for usage.|
- Create a boilerplate for
Express API Versioningwith
Temitayo Fadojutimi is a Software Developer at Andela and he dedicates his expertise to solving practical problems in the society. He tweets at @adesege_
To test this package,
- Clone this repo or
npm install express-api-versioning
- cd into the package directory and run
- Then run
npm testto run the test.
Thank you for your interest in contributing to this package. I currently accept contributions from everyone but I expect that standards are maintained. To contribute,
- Fork the project
- Create a feature branch, branch away from
- Write tests, using
Mocha and Chaior any other testing frameworks, and code
- If you have multiple commits please combine them into a few logically organized commits by squashing them
- Push the commit(s) to your fork
- Submit a merge request (MR) to the
- The MR title should describe the change you want to make
- The MR description should give a motive for your change and the method you used to achieve it.
- Mention the issue(s) your merge request solves, using the
Closes #XXXsyntax to auto-close the issue(s) once the merge request will be merged.
- Be prepared to answer questions and incorporate feedback even if requests for this arrive weeks or months after your MR submission
- If a discussion has been addressed, select the "Resolve discussion" button beneath it to mark it resolved.
- When writing commit messages please follow these guidelines.