Book Image

Mastering Web Application Development with Express

By : Alexandru Vladutu
Book Image

Mastering Web Application Development with Express

By: Alexandru Vladutu

Overview of this book

Table of Contents (18 chapters)
Mastering Web Application Development with Express
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

API versioning


At this time, the URLs of the SmartNotes application are not prefixed with anything, so it will be hard to add a new version of our API.

Normally, we should always have in mind that APIs deprecate over time and new versions are released. Fortunately, since Express applications can be mounted onto others, we can achieve this by modifying a code segment in server.js. All we have to do is replace app.listen(config.port) with the following code:

var masterApp = express();
masterApp.use('/api/v1/', app);
masterApp.listen(config.port);

Now, instead of making a GET HTTP request to /users/johndoe, for retrieving user information (for example), the API clients will make a request to /api/v1/users/johndoe. This means that when a new version of the API is available, we can make it available using the /api/v2/ prefix, so it's mission accomplished!

Note

Remember to update the functional tests after doing this; otherwise, they will fail because they will be sending requests to the old URLs.