Skip to content

Instantly share code, notes, and snippets.

@superkhau
Last active August 21, 2017 07:51
Show Gist options
  • Save superkhau/8ba255690d44e09bb036 to your computer and use it in GitHub Desktop.
Save superkhau/8ba255690d44e09bb036 to your computer and use it in GitHub Desktop.
LoopBack - API versioning

Create config.local.js with the following:

var p = require('../package.json');
var version = p.version.split('.').shift();

module.exports = {
  restApiRoot: '/api' + (version > 0 ? '/v' + version : ''),
  host: process.env.HOST || 'localhost',
  port: process.env.PORT || 3000
};

API path's will look like /api/v1 using the app's major version. If the app's major version is 0, then the path is simply /api.

@bkvaiude
Copy link

How can it helpful in the following scenario?

Android 4.5.6 version
GET http://localhost:3000/api/v1/Users

Android 4.6.1 version
GET http://localhost:3000/api/v2/Users

For iPhone X versioin
GET http://localhost:3000/api/v3/Users

Based on package.json logic, do I need to run loopback on three different instances for each version (v1, v2, v3)?

@shrimaliakash
Copy link

shrimaliakash commented Aug 21, 2017

How can access api versioning in that way in postman??

@shrimaliakash
Copy link

app.all('/api/:version/:controller*?'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment