Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST - web service response - mime type?

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
like image 261
001 Avatar asked Oct 24 '10 04:10

001


People also ask

What is mime type in REST API?

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.

Which MIME type is used in REST Web service by default return response to the client?

By default, a RESTful resource is published or consumed with the */* MIME type.

Which data format does REST API use?

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.


1 Answers

  1. 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.

  1. 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

like image 163
Day Avatar answered Sep 22 '22 13:09

Day