REST - web service response - mime type?

json, mime-types, rest, web-services, xml

Solution

- Is it important to set the correct mime type for a web service response?

Absolutely yes. If you are doing a true REST API then documentation of the different Media Types you return is a vital part of your API specification.

- what is the correct mime type for a, a) XML response? b) JSON response?

For a true REST service, it depends on the details of your API and what you've defined as your content-types.

As an example (taken from this excellent article that is worth reading in full), a Bank may want to define a Content-Type for bank accounts of `application/vnd.bank.org.account+xml`. Note how the MIME type "ends with `+xml`, and as per RFC 3023, XML processors (including XMLHttpRequest) can handle such representations as though it is XML". The same bank might also use XML to represent a bank transfer, this time using a Content-Type of `application/vnd.bank.org.transer+xml`

Problem

1) Is it important to set the correct mime type for a web service response? 2) what is the correct mime type for a, a) XML response? b) JSON response? ``` application/xml text/xml application/json application/x-javascript text/javascript text/x-javascript text/x-json ```

Original source

Related problems