CouchDB HTTP API
CouchDB's API is made available using a RESTful HTTP interface. This HTTP API outlines how an HTTP request is processed.
HTTP Request Message
An HTTP request contains the following elements:
1. Request line indicating the method, resource, and HTTP version of the request.
2. Headers, such as content-type and content-length.
3. An empty line.
4. The message body.
A Simple HTTP Request :
POST /db HTTP/1.1 content-type : application/json {"type": "category", "name": "Web Tutorials", "slug": "web-tutorials"}
HTTP Request Methods :
The table describes the HTTP request methods used in CouchDB. Please note that the COPY method is not part of the HTTP standard, but rather an extension to HTTP used by CouchDB.
Methods | Description |
---|---|
GET | GET requests are typically used for side-effect-free transactions, such as retrieving data. In CouchDB, a GET request is used to request data from a database. |
POST | In CouchDB, POST requests are used to create new resources, usually where the request's URL is different for the resource that is to be created. |
PUT | Along with the data included in the message body, PUT requests are also used to submit data to a resource.Usually PUT requests are used to update existing data, URL is requested from the same resource |
DELETE | DELETE requests are used to delete a specified resource. Use DELETE request to delete CouchDB database and documents. |
COPY | This non-standard extension of HTTP is used by CouchDB to copy one resource to another. |
HTTP Response :
An HTTP response consists of a status line, a header, and a body. The headers usually provide information such as response time, information about the server, type of content contained in the response body, and more meta information. The response message returns to the body.
A Simple HTTP Response :
HTTP/1.1 200 0K Server: couchDB/0.9.0 (Erlang OTP/R13B) Date: sun, 04 Oct 2019 20:50:00 GMT Content-Type: text/plain;charset=utf-8 Content-Length: 40 Cache-control: must-revalidate {"couchdb": "Welcome" , "version": "0.9.0"}
HTTP Status Codes :
The table describes the HTTP status codes that CouchDB uses to indicate the success or failure of a database transaction.
Status Codes | Description |
---|---|
200 (0K) | The request was successfully processed. |
201 (Created) | The document was successfully created. |
202 (Accepted) | The database was successfully compacted. |
304 (Not Modified) | The document has not been modified since the last update. |
400 (Bad Request) | The syntax of the request was invalid or could not be processed. |
404 (Not Found) | The requested resource was not found. |
405 (Method Not Allowed) | The request was made using an incorrect request method. |
409 (Conflict) | The request failed because of a database conflict. |
412 (Precondition Failed) | Could not create database—a database with that name already exist. |
500 (Internal Server Error) | The request was invalid and failed, or an error occurred within the CouchDB server that prevented it from processing the request. |
Visit :
Discussion