The FooBar Api is Published
Let's say there's a team of developers working on an API, called the FooBar api
with a few endpoints:
GET /foo
# returns {'bar': '/bar', 'data': 'foo'}
GET /bar
# returns {'data': 'hello world!'}
Now, let's say the FooBar api
exploded and became hugely popular. Developers from all around the world are using the FooBar api
and now thousands of projects are completely dependent on it.
The Problem
The FooBar api
recently got a new project manager. He says, that it is now desired that the responses return a message
instead of data
, because message
is "more descriptive." Unfortunately, any change to the FooBar
API could break thousands of these projects. Even though all of these developers whose projects were broken would mostly be patient and understanding about the change, the FooBar
team doesn't want to break their own dependent projects and decide it's best to keep the api backwards compatible.
The Solution
The FooBar api
needs to be versioned. Unfortunately there is no good way to do this. Luckily for the FooBar
team, their project manager knows best and decided that the versioning should be accomplished by placing a version number in the url since "that's the part he can see." So, once the second version of the FooBar api
is complete, the two versions should look something like this:
FooBar v1
GET /foo
# returns {'bar': '/bar', 'data': 'foo'}
GET /bar
# returns {'data': 'hello world!'}
FooBar v2
GET /v2/foo
# returns {'bar': '<url to bar>', 'message': 'foo'}
GET /v2/bar
# returns {'message': 'hello world!'}
The Second Problem
The FooBar
team has another problem now; they don't know what should go in <url to bar>
. Of the roughly infinite possible permutations of characters, they were impressively able to get it down to two choices - /v2/bar
and /bar
.
The Question
What are the pro's and cons of using /v2/bar
vs /bar
?