Note that there are some explanatory texts on larger screens.

plurals
  1. POREST and multiple data formats
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <p>Question is: what is the recommended style to achieve this ? Three choices (more from your helpful suggestions)</p> <ol> <li>option in the URL (e.g. <a href="http://example.com/questions/12345/?format=json" rel="noreferrer">http://example.com/questions/12345/?format=json</a> )</li> <li>different interface (e.g.: for json data you have <a href="http://example.com/questions/1234/json/" rel="noreferrer">http://example.com/questions/1234/json/</a> or <a href="http://example.com/json/questions/12345/" rel="noreferrer">http://example.com/json/questions/12345/</a>, for xml data you have <a href="http://example.com/questions/1234/xml/" rel="noreferrer">http://example.com/questions/1234/xml/</a> etc... you get the point)</li> <li>http header Accept: application/json</li> </ol> <p>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.</p> <p>Thanks!</p> <p><em>Edit</em>: Additional proposal is the following</p> <p>4) Specify a proper URL for each format e.g. <a href="http://example.com/questions/12345.json" rel="noreferrer">http://example.com/questions/12345.json</a> . This looks nice, but wouldn't this mean that, for consistency, we should also have <a href="http://example.com/questions/12345.html" rel="noreferrer">http://example.com/questions/12345.html</a> ? sounds so 1995... :)</p> <p>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. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload