I've been reading up on API versioning for REST APIs.
Most of the articles I've come across (here's an example) seem to focus on two options:
- URI based versioning, e.g.
v1/my_resource/ - Media Type Versioning, i.e. adding additional information to the
ACCEPTheader.
I have also seen proposals of adding a custom version parameter or header.
Generally though, from a philosophical point of view, one appears to end up in Non-RESTful territory with significant complexity and caching implications, and REST puritans would insist that versioning is wrong and you need to maintain backwards compatibility (here's Roy Felding's words on the matter).
One thing I haven't seen mentioned is using the data payload as a solution to the problem of changing your functionality while keeping backwards compatibility.
Take the following example JSON body:
{
"v15": {
"field2": "abc",
"field3": 42
},
"v14": {
"field1": "code still supports me",
"field2": "abc"
}
}
The idea here would be to have the newer API consumers act on the v15 data and the older consumers will still get their required v14 data while ignoring the v(n > 14) data by design. Of course, the drawback is that both the producer and consumer code will need to be able to handle two or more versions of the data.
Still, the tradeoff on the face of it seems appealing to me. I am sceptical, however, since I haven't seen this solution described in any articles I've found.
My question is: What am I missing? Is this a bad solution for evolving a service?