Suppose I have a RESTful web service that contains information about an object that can be accessed at a URL, such as http://example.com/myobject . I would like to receive this information in two formats: firstly, simple data in XML format, and secondly, as a full HTML page, which can also include a javascript interface for modifying an object and PUT it back with AJAX.
What is the canonical way to achieve this? Do I have to publish my object in two different URLs, for example http://example.com/myobject?format=xml and ... format = html? (Are there any more efficient ways than using the query string to distinguish URLs here?) Or is it wise to send something like multi-page MIME data and I can rely on the ability of the browser to extract part of the HTML? Or is there some kind of HTTP header field in the request that I could use?
(With PUT or POST requests sent in different formats, this is much simpler, since the server can check the format and parse it accordingly.)
source
share