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
A media type (also known as a Multipurpose Internet Mail Extensions or MIME type) indicates the nature and format of a document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838.
By default, a RESTful resource is published or consumed with the */* MIME type.
The REST API supports the following data formats: application/json. application/json indicates JavaScript Object Notation (JSON) and is used for most of the resources. application/xml indicates eXtensible Markup Language (XML) and is used for selected resources.
- 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With