tags:

views:

84

answers:

3

I have a REST api that will accept a version via a custom HTTP header or a request parameter. I'm doing this because I don't want the URI to contain the version like del.icio.us .e.g http://server/api/v1/...

Now in my design, the HTTP header has a higher priority than the request param. What happens then if the user does not supply any version at all ? Should I default to the oldest version, or default to the latest version ?

+1  A: 

Why not simply make the version required and throw an error if it's not there?

If that's not an option then you have to go with the oldest version, otherwise if you upgrade and don't maintain backwards compatability you'll break existing clients.

Of course, if you don't mind breaking existing clients it might be more convenient to go with the latest version.

Greg
I don't want to throw an error if it's missing. The app should degrade gracefully. I think you've convinced me to go with the oldest version.
Jacques René Mesrine
+1  A: 

Don't version the URI at all. Instead just version the representation. This way the client can decide which version of the API they want to use and it degrades well.

Example:

GET /contacts/3 HTTP/1.1
Accept: application/myapp-v2+xml

HTTP/1.1 200 OK
Content-Type: application/myapp-v2+xml
efleming969
A: 

If your API defines specific URIs or URI naming conventions for accessing resources, your API is not RESTful. Versioning of URI construction is a non-issue for any REST API. Please see http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven for more information.

Wahnfrieden