We are standing in front of implementing versioning to our REST API (in URL versioning schema).
/api/v1.2/users (implements /list)
/api/v2.0/users (might implement new endpoint /filter)
/api/v2.1/users
I'm looking for solution where I would be able to write code like this:
const client = apiClient(apiUrl, version=1.2)
client.list()
client.filter(...) # undefined
const client = apiClient(apiUrl, version=2.0)
client.list()
client.filter(...) # defined
Daniel J Dominguez
A way that you could do it would be through a method called content negotiation, and is part of the HTTP standard. Rather than versioning the whole URL branch, you send the packet to the same URL, but with a header of "Accept" and a value of what you want back; so it could be "Accept: application/vnd.org.app.Person-v2+json". This would tell the server that the user wants v2 of your Person object. This allows more flexibility in when your api moves to v2, and which object actually need that v2 status. Of course, the downside is that this will require some more coding on your side, if you are unable to find a good library that will do this for you. Most people go for url versioning, because it is easier, but Content Negotiation allows a greater control over what happens, and could be used for serving different formats of the same image as well. If you want to read some more on this, just Google "HTTP Content Negotiation Versioning"