4 ms·
good point, but the point of a restful resource is that the url represents a resource, but then w/accept header versioning, i now need two pieces of data, one o
by rubyrescue 15y ago
good point, but the point of a restful resource is that the url represents a resource, but then w/accept header versioning, i now need two pieces of data, one of which isn't visible, to properly represent and retrieve a resource.
I guess my point is that if i have to pick, i'd rather occasionally have two request urls with a minor version difference that are actually the same resource than two urls that appear to be the same resource but are not because one was requested with a header that affects the returned data.
- icebraining 15y agoYou're confusing resource with representation. An URL is a resource, but if the representation of that is a JSON document or a picture of him/her, that's up to the server. Just because an header affects the representation of a resource, doesn't mean they're different resources.
- rubyrescue 15y agoactually that's a good example that makes my point. if i said to you - well if you want to retrieve a person's user information, just GET /users/1 with Accept: text/json. If you want their photo, just GET /users/1 with Accept: image/jpeg - philosophically, i'm not violating the 'rules of REST' but it feels wrong to me.
- icebraining 15y agoSure, I would create a "User's photo" resource too and link it from /users/1, but that's because a user's photo can be a new resource, so it can have its own URL.
- stanleydrew 15y agoWhat do you mean by visible? Visible in the URL bar of a browser? The headers are all there in the request, for all to see.
- rubyrescue 15y agoyes i'm thinking more pragmatically. From an API perspective the header is part of the request but given that the human-readability of urls is a feature of http, it just somehow feels wrong to me to modify the response based on a request header.
- glassx 15y agoI think most developers don't see that as a problem. We modify the response all the time based on headers like User-Agent, Referer, If-Unmodified-Since, Accept-Language and others, so using Accept for versioning isn't really that strange.
- Dylan16807 15y agoUser-Agent: modifying based on this is a Bad Thing Referer, If-Unmodified-Since: these only decide if you respond or don't or error, they don't generally change a successful transfer Accept-Language: I was under the impression that this was buggy and not well-supported, but it is a good example in theory
- icebraining 15y agoThe response is changed all the type depending on the value of the Cookie header.