According to this excellent presentation on designing RESTful interfaces, the preferred way to implement versioning is to utilize the Accept-header, using something like:
GET /products HTTP/1.1
Host: example.com
Accept: application/vnd.com.myservice.v2+xml
This works perfectly for XML Content-Types, but is possible to use the same scheme for versioning the JSON-equivalent?
I.e, is it possible to ask for:
GET /products HTTP/1.1
Host: example.com
Accept: application/vnd.com.myservice.v2+json
The response would be something like:
HTTP/1.1 200 OK
Content-Type: application/vnd.com.myservice.v2+xml; charset=UTF-8
Allow: GET, POST
<?xml version="1.0" encoding="utf-8"?>
<products xmlns="urn:com.example.products"
xmlns:xl="http://www.w3.org/1999/xlink">
<product id="1234" xl:type="simple"
xl:href="http://example.com/products/1234">
<name>Red Stapler</name>
<price currency="EUR">3.14</price>
<availability>false</availability>
</product>
</products>
and the JSON equivalent (sort of):
HTTP/1.1 200 OK
Content-Type: application/vnd.com.myservice.v2+json; charset=UTF-8
Allow: GET, POST
[
{
id: "1234",
links: [
{
rel: "self",
href: "http://example.com/products/1234"
}
],
name: "Red Stapler",
price: {
currency: "EUR",
value: 3.14
},
availability: false
}
]