REST worst practices
jacobian.org
jacobian.org
I have to disagree. First of all, do not assume anything based on mime types the browser (or whatever user agent) asked for. It's very hacky to expect consumers to mess with their user agent's Accepts header to get the response format they want. Specifying the desired format such as ?format=xml is simple, clear, specific, and reliable. I prefer default format be XML and other formats available by passing a format parameter.
The REST of article has some good suggestions. I made a pun there. Did you catch it? "REST of the article". Because it's about REST? That's comedy gold.
Unless he really thinks that determining what format to send the response in from the HTTP header is an overwhelmingly arrogant move...
Third time's a charm! :P
If you want to put the output format into the URL, I like the .json .xml extensions better. Not that there's anything wrong with the request parameter approach, but the file extension approach also plays nice with user OSes.
Also, I'd ideally use both approaches. So the consumer can pick between using /resouce/1 with an Accept header, or just using /resource/1.xml /resource/1.json directly. The nice thing about the Accept header is that file extensions can have some ambiguity whereas the MIME types are pretty standard and come with RFCs backing them up.
Including the link URL as a template in a separate field is a potential possibility, but (a) it will add a ton of duplicated data to collections results, (b) it relies on your consumer parsing and inserting the field into their call every time, which if they care about the efficiency of their own code they're probably not going to do, so you don't get any added flexibility.
But I will share something a colleague just said because it made me laugh: "I have kids dude, so I'm used to hearing people argue vigorously about stupid stuff. This whole REST dicussion has the feeling of a bunch of nerds arguing about which Star Trek movie is worst."
Again, I don't really want to get into a discussion with you REST fanatics, hopefully the upvotes from people who chuckle will cancel out the downvotes from the REST people.