Content-type
Specifies the content type of the information being supplied
within the request. The specification uses MIME type
specifications. For the majority of requests this will be
JSON (application/json
). For some
settings the MIME type will be plain text. When uploading
attachments it should be the corresponding MIME type for the
attachment or binary
(application/octet-stream
).
The use of the Content-type
on a request
is highly recommended.
Accept
Specifies the list of accepted data types to be returned by the server (i.e. that are accepted/understandable by the client). The format should be a list of one or more MIME types, separated by colons.
For the majority of requests the definition should be for
JSON data (application/json
). For
attachments you can either specify the MIME type explicitly,
or use */*
to specify that all file types
are supported. If the Accept
header is
not supplied, then the */*
MIME type is
assumed (i.e. client accepts all formats).
The use of Accept
in queries for CouchDB
is not required, but is highly recommended as it helps to
ensure that the data returned can be processed by the
client.
If you specify a data type using the
Accept
header, CouchDB will honor the
specified type in the Content-type
header
field returned. For example, if you explicitly request
application/json
in the
Accept
of a request, the returned HTTP
headers will use the value in the returned
Content-type
field.
For example, when sending a request without an explicit
Accept
header, or when specifying
*/*
:
GET /recipes HTTP/1.1 Host: couchdb:5984 Accept: */*
The returned headers are:
Server: CouchDB/1.0.1 (Erlang OTP/R13B) Date: Thu, 13 Jan 2011 13:39:34 GMT Content-Type: text/plain;charset=utf-8 Content-Length: 227 Cache-Control: must-revalidate
Note that the returned content type is
text/plain
even though the information
returned by the request is in JSON format.
Explicitly specifying the Accept
header:
GET /recipes HTTP/1.1 Host: couchdb:5984 Accept: application/json
The headers returned include the
application/json
content type:
Server: CouchDB/1.0.1 (Erlang OTP/R13B) Date: Thu, 13 Jan 2011 13:40:11 GMT Content-Type: application/json Content-Length: 227 Cache-Control: must-revalidate