Reputation: 53
I have created API for User and i need to include version number for this API in response. Is it good way or should we just follow version number in request ?
Upvotes: 2
Views: 4815
Reputation: 1293
See REST API Versioning (restfulapi.net/versioning/) :
URI Versioning
Using the URI is the most straightforward approach (and most commonly used as well) though it does violate the principle that a URI should refer to a unique resource. You are also guaranteed to break client integration when a version is updated.
e.g.
http://api.example.com/v1 http://apiv1.example.com
The version need not be numeric, nor specified using the “v[x]” syntax. Alternatives include dates, project names, seasons or other identifiers that are meaningful enough to the team producing the APIs and flexible enough to change as the versions change.
Versioning using Custom Request Header A custom header (e.g.
Accept-version) allows you to preserve your URIs between versions though it is effectively a duplicate of the content negotiation behavior implemented by the existing Accept header.
e.g.
Accept-version: v1 Accept-version: v2
Versioning using Accept header
Content negotiation may let you to preserve a clean set of URLs but you still have to deal with the complexity of serving different versions of content somewhere. This burden tends to be moved up the stack to your API controllers which become responsible for figuring out which version of a resource to send. The end result tends to be a more complex API as clients have to know which headers to specify before requesting a resource.
e.g.
Accept: application/vnd.example.v1+json Accept: application/vnd.example+json;version=1.0
Upvotes: 5