Database / CouchDB Interview Questions
What is the CouchDB HTTP REST API and how do you perform basic CRUD operations?
CouchDB maps every database operation to a standard HTTP method and URL. The server root is typically http://localhost:5984. No driver installation is required — curl or any HTTP client works directly.
# Create a database
curl -X PUT http://admin:pass@localhost:5984/inventory
# {"ok":true}
# Create a document with a specific _id (PUT)
curl -X PUT http://admin:pass@localhost:5984/inventory/item:001 \
-H "Content-Type: application/json" \
-d '{"type":"item","name":"Widget","stock":150}'
# {"ok":true,"id":"item:001","rev":"1-3c6a8..."}
# Create a document with auto-generated _id (POST)
curl -X POST http://admin:pass@localhost:5984/inventory \
-H "Content-Type: application/json" \
-d '{"type":"item","name":"Gadget","stock":30}'
# Read a document
curl http://admin:pass@localhost:5984/inventory/item:001
# Returns JSON with _id and _rev
# Update — _rev is mandatory in the body
curl -X PUT http://admin:pass@localhost:5984/inventory/item:001 \
-H "Content-Type: application/json" \
-d '{"_rev":"1-3c6a8...","type":"item","name":"Widget","stock":200}'
# {"ok":true,"id":"item:001","rev":"2-9b4f1..."}
# Delete — pass _rev as query param
curl -X DELETE "http://admin:pass@localhost:5984/inventory/item:001?rev=2-9b4f1..."
# {"ok":true,"id":"item:001","rev":"3-d2e79..."}
# Bulk upsert
curl -X POST http://admin:pass@localhost:5984/inventory/_bulk_docs \
-H "Content-Type: application/json" \
-d '{"docs":[{"type":"item","name":"Part-A"},{"type":"item","name":"Part-B"}]}'
HTTP status codes follow REST conventions: 201 Created on success, 200 OK for reads, 404 Not Found, and 409 Conflict when the supplied _rev does not match the server's current revision. The _bulk_docs endpoint accepts thousands of documents per request, dramatically reducing round-trips for bulk loads.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
