CouchDB REST API for Document CRUD Operations — Examples With Postman
In this tutorial, we will learn how to perform CRUD operations with the help of HTTP requests firing from Postman.
Join the DZone community and get the full member experience.
Join For FreeIn this tutorial, we will learn how to perform CRUD operations with the help of HTTP requests firing from Postman.
Assumptions
- The CouchDB Server is running at
http://127.0.0.1:5789/
- Database name is
tutorialkart
. - The database contains the following two documents (viewed in table view).
View Document — GET Request
Request type: GET
URL: http://hostname_or_IP:Port/databasename/document_id/
URL for this Example: http://127.0.0.1:5984/tutorialkart/0001/
Update Document — PUT Request
Request type: PUT
URL: http://hostname_or_IP:Port/databasename/document_id/
URL for this Example: http://127.0.0.1:5984/tutorialkart/0001/
Request Body:
xxxxxxxxxx
{
"_rev": "2-74fe79dd659ef45ae32956d3ad4985ab",
"category": "NoSQL Databases"
}
_rev has to be sent for the document which you would like to edit, along with the fields that need an update. You will get _rev when you GET the document.
Delete Document — PUT Request
Request type: DELETE
URL: http://hostname_or_IP:Port/databasename/document_id/?rev=revsion_number
URL for this Example: http://127.0.0.1:5984/tutorialkart/0001/?rev=3-d740acd633d56c9522915fa9fc4579e7
_rev has to be sent for the document which you would like to delete as a parameter in the request.
Create Document — PUT Request
Request type: PUT
URL: http://hostname_or_IP:Port/databasename/new_document_id/
URL for this Example: http://127.0.0.1:5984/tutorialkart/0003/
Request Body:
{
"tutorial": "Spark Tutorial",
"category": "Big Data",
"topics": 4
}
_rev has to be sent for the document which you would like to edit, along with the fields that needs an update. You will get _rev when you GET the document.
Conclusion
Concluding this article, we have learned how to make CRUD operations for a document in CouchDB Database, with the help of Postman.
Opinions expressed by DZone contributors are their own.
Comments