2.2.5.1 Accept
A primary goal of data services is to allow a client of the service to focus on the data being transmitted and not be required to understand a single data format. As such, the OData protocol that is defined in this document enables exchanging resources using AtomPub semantics in multiple serialization formats (AtomPub, JSON, Verbose JSON, and so on).
The nature of the client application using a data service and its runtime environment determines which format is best. For example, Asynchronous JavaScript (AJAX)-based applications that run inside web browsers might find JSON easier to use because this format can be directly turned into JavaScript objects. On the other hand, a client application might be written with a language/runtime library that has a rich, built-in XML parser, making an XML-based format an appropriate choice.
The OData protocol uses the Accept request-header field, as specified in [RFC2616]. Once a requested format is determined using the rules specified in [RFC2616], the following Accept Request Header to Content-Type Response Header Mapping table is used to determine the value of the Content-Type response header and the format of the response payload.
Value of Accept request header |
Value of Content-Type response header |
---|---|
*/* Specified in [RFC2616] and [RFC2045] |
|
text/* Specified in [RFC2046] |
Behavior is not defined by this document |
application/* Specified in [RFC2046] |
Behavior is not defined by this document |
text/plain Specified in [RFC3676] |
text/plain |
text/xml Specified in [RFC3023] |
text/xml |
application/xml Specified in [RFC3023] |
application/xml |
application/atom+xml Specified in [RFC5023] |
application/atom+xml |
application/atom+xml;type=entry Specified in [RFC5023] |
application/atom+xml;type=entry |
application/atom+xml;type=feed Specified in [RFC5023] |
application/atom+xml;type=feed |
Specified in [RFC4627] |
For OData 1.0 and OData 2.0 responses: application/json;odata=verbose For OData 3.0 responses: application/json |
application/json;odata=verbose |
Table: Accept Request Header to Content-Type Response Header Mapping
If the server cannot send a response that is acceptable, as indicated in the preceding Accept Request Header to Content-Type Response Header Mapping table and according to the Accept header value, then, as specified in [RFC2616], the server SHOULD return a 4xx response.
The OData protocol can be extended to support arbitrary message formats. However, the scope of this section is to define the use of the application/atom+xml (section 2.2.5.1.1), application/json (section 2.2.5.1.2), and application/json;odata=verbose (section 2.2.5.1.3) formats. A data service MAY accept requests with Accept header values other than those shown in the preceding table. The returned Content-Type response header value for such requests is not defined by this specification.