While looking through other people’s code, I noticed that some code their javascript/backbone.js in such a way that is is easy to change the version of their serverside API.
API_URL = '/api/v2/';
Question: What is the purpose of being able to change the version of the API used from v2 to v1 or v3 so easily but not able to change the clientside code as easily?
Here’s an example of a backbone.js snippet:
var POST_API = '/api/v1/post/'
window.Post = Backbone.Model.extend({
url: POST_API
})
window.Posts = Backbone.Collection.extend({
model: Post,
url: POST_API
})
The purpose is that when the API is upgraded, services or scripts (mostly from third parties) will still be able to use the olds API.
This mean, this way of using a version name in the API url let you update your API without breaking legacy code/apps (as long the old version is still available).