CouchDB - HTTP API
CouchDB - HTTP API
Following are the different request formats of HTTP Protocol used to communicate with
CouchDB.
GET − This format is used to get a specific item. To get different items, you have to
send specific url patterns. In CouchDB using this GET request, we can get static
items, database documents and configuration, and statistical information in the form
of JSON documents (in most cases).
HEAD − The HEAD method is used to get the HTTP header of a GET request without
the body of the response.
POST − Post request is used to upload data. In CouchDB using POST request, you
can set values, upload documents, set document values, and can also start certain
administration commands.
PUT − Using PUT request, you can create new objects, databases, documents,
views and design documents.
DELETE − Using DELETE request, you can delete documents, views, and design
documents.
COPY − Using COPY method, you can copy documents and objects.
Content-type − This Header is used to specify the content type of the data that we
supply to the server along with the request. Mostly the type of the content we send
along with the request will be MIME type or JSON (application/json). Using Content-
type on a request is highly recommended.
Accept − This header is used to specify the server, the list of data types that client
can understand, so that the server will send its response using those data types.
Generally here, you can send the list of MIME data types the client accepts,
separated by colons.
Though, using Accept in queries of CouchDB is not required, it is highly recommended
to ensure that the data returned can be processed by the client.
Explore our latest online courses and learn new skills at your own pace. Enroll and become
a certified expert to boost your career.
Response Headers
These are the headers of the response sent by the server. These headers give information
about the content send by the server as response.
Content-type − This header specifies the MIME type of the data returned by the
server. For most request, the returned MIME type is text/plain.
Cache-control − This header suggests the client about treating the information sent
by the server. CouchDB mostly returns the must-revalidate, which indicates that the
information should be revalidated if possible.
Content-length − This header returns the length of the content sent by the server,
in bytes.
Etag − This header is used to show the revision for a document, or a view.
Status Codes
Following is the tabular form of the status code sent by the http header and the description
of it.
200 − OK
1
This status will be issued when a request completed successfully.
201 − Created
2
This status will be issued when a document is created.
202 − Accepted
3
This status will be issued when a request is accepted.
This status is issued when the HTTP request type used is invalid.
409 − Conflict
6
This status is issued whenever there is any update conflict.
PUT /db
1
This url is used to create a new database.
GET /db
2
This url is used to get the information about the existing database.
PUT /db/document
3
This url is used to create a document/update an existing document.
GET /db/document
4
This url is used to get the document.
DELETE /db/document
5
This url is used to delete the specified document from the specified database.
GET /db/_design/design-doc
6
This url is used to get the definition of a design document.
GET /db/_design/designdoc/_view/view-name
7 This url is used to access the view, view-name from the design document from
the specified database.