Hi guys,
Ok, here is the fact. StackOverflow is implemented REST-style. When you visit a specific questions/$id/ URL you get to see the question. The content is returned in HTML because it's what the browser understands.
I have to develop my own REST service. Fact is that I have to return multiple formats for the same information. For example, the default could be HTML, but I could return also an XML or a JSON.
Question is: what is the recommended style to achieve this ? Three choices (more from your helpful suggestions)
- option in the URL (e.g. http://example.com/questions/12345/?format=json )
- different interface (e.g.: for json data you have http://example.com/questions/1234/json/ or http://example.com/json/questions/12345/, for xml data you have http://example.com/questions/1234/xml/ etc... you get the point)
- http header Accept: application/json
Same is for PUT (POST) operations. If I want to submit data in different formats, I need to inform the receiver the format I am providing, so the same situation (and question) holds.
Thanks!
Edit: Additional proposal is the following
4) Specify a proper URL for each format e.g. http://example.com/questions/12345.json . This looks nice, but wouldn't this mean that, for consistency, we should also have http://example.com/questions/12345.html ? sounds so 1995... :)
PS: I hate markdown putting an arbitrary order to the list. If I want to start with 4, I should be able to do it.