2 ms·
Ask HN: Versioning API URL vs. Header + MIME Type
Hi,
I'm developing a RESTful API and one of the requirements is that it has to be versioned.
The usual solution is to add the version in the URI, http://example.com/api/v1/resource
But it doesn't feel completely right. The resource probably will be the same in another version just its representation or the parameters will change.
Then, I thought about using the Accept header with vendor specific MIME types to specify what API version to use. This way the resource will never change and it will be unique.
A simplified example of usage would be:
GET http://example.com/resource
Accept: application/vnd.example-api-v1.text+json
Update: formatting.
- madhouse 15y agoYou could even use something like "Accept: application/vnd.text+json;api-version=1". Personally, I'd go with the custom Accept header, using the same type, but different "accept-extension" (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html for details).
- edu 15y agoGood point, actualy Zend is doing it exactly like this: http://files.zend.com/help/Zend-Server-Community-Edition/api_versioning_negotation.htm http://files.zend.com/help/Zend-Server-Community-Edition/api...