I have a RESTful web service deployed at http://example.com/v1/SomeResource. One day, a new protocol version (that is not backwards compatible) is deployed to http://example.com/v2/SomeResource. From the client of view, this upgrade could occur at any time between two HTTP requests.
How does the server indicate to the client that it no longer supports v1 calls and the client is expected to upgrade to v2? Is there an appropriate response code I can use?
I would want to provide the client with the following information:
- An incompatible upgrade has taken place. There is no way for the client to use the new service because the protocol could be totally different.
- The URL of the new client software.
- A message explaining to the users that they must upgrade.
I recommend the following article by Peter Williams
I think you shouldn't do this in the first place, but probably it's too late.
From the article RESTful Web services: The basics.
Best practice:
It's probably better to keep the versioning out of the URL and to make the new resources backwards compatible with the old.
Backwards compatible:
If you must keep the v1 in the URL, and are making v2 URLs, then you have to decide whether you want to support both formats, or make the old v1 obsolete. If you decide on making the old v1 obsolete then I would recommend to return 303 or 401 for anyone requesting a v1 URL.
Making old URLs obsolete:
I would recommend using 303 See Other. Or if there is no associated redirect, then use 410 Gone.
Source
Document everything:
The main thing to be concerned about is whatever you chose to return, just document it in your documentation. You can decide how you want your service to work, others that want to consume it will follow the documentation.
I would recomend instead the use of the 301 (301 Moved Permanently). Read why.
Hope it helps, Bruno Figueiredo