Explore essential concepts of the CouchDB API, focusing on REST architecture and HTTP interactions. This quiz covers key methods, data formats, request-response patterns, and basic error handling for those learning about CouchDB's web interface.
Which HTTP verb would you use to retrieve a document from a database using a RESTful API?
Explanation: GET is the standard HTTP method for retrieving resources from a server in RESTful APIs. MAKE and SEND are not valid HTTP methods, while FETCH, though it sounds similar, is not an official HTTP verb. GET allows you to access information without modifying it, making it the appropriate choice here.
When working with the CouchDB API, what is the default data format used for sending and receiving documents?
Explanation: JSON is the default and most commonly used data format for CouchDB API communications. XML, CSV, and YAML are other data formats, but they are not the default for this context. JSON's lightweight, human-readable structure makes it ideal for RESTful APIs.
Which HTTP method should you use to create a new document in a database via HTTP?
Explanation: POST is used to create new resources, such as documents, in RESTful APIs. GET retrieves data, PATCH modifies existing data partially, and LOAD is not an HTTP verb. Only POST is suitable for creating new entries in the database.
If you want to access a specific document with ID 'book1' in the 'library' database using a RESTful API, what is a proper resource path example?
Explanation: The typical RESTful resource path format is '/database/documentID', making '/library/book1' correct. '/book1/library' reverses the order and is incorrect, '/library:book1' uses the wrong separator, and '/dbs/library/book1' adds an unnecessary segment. The straightforward path follows the standard convention.
Which HTTP method is most appropriate for replacing an entire existing document in a database?
Explanation: PUT is used to replace an entire resource or document, making it the right choice for full document updates. PATCH would only partially update a document, GET simply retrieves data, and HEAD just fetches headers. Therefore, PUT is the only method suited for fully replacing a document.
To remove a document from a database using the API, which HTTP method should you use?
Explanation: DELETE is the standard HTTP method for removing resources in RESTful APIs. REMOVE, TAKE, and DROP are not official HTTP methods, despite sounding related to deletion. Only DELETE will successfully instruct the server to remove a document.
What HTTP status code indicates a successful document creation using a POST request?
Explanation: A 201 status code specifically means 'Created' and is returned after a successful POST that results in a new resource. A 404 means 'Not Found,' 400 means 'Bad Request,' and 503 signals 'Service Unavailable.' Only 201 indicates successful creation.
Which HTTP header should be set to indicate you are sending data in JSON format?
Explanation: The correct way to specify the body is JSON is to use the 'Content-Type: application/json' header. 'Accept: application/html' refers to expected response type, not the request format. 'Set-Cookie' is unrelated to data format, and 'Host' specifies the server address.
If an API request receives a 401 Unauthorized response, what does it typically mean?
Explanation: A 401 status code indicates that authentication is required and the provided credentials are missing or invalid. It does not mean the server is offline (that would generally result in a timeout), an incorrect URL (which could result in a 404), or a full database. Therefore, missing credentials is the direct cause.
When making an HTTP request to retrieve a non-existent document, which status code will likely be returned?
Explanation: A 404 status code means 'Not Found' and is typical when a requested document does not exist. 200 indicates success, 500 points to a server error, and 201 indicates the creation of a new resource. 404 is the only status tied directly to missing resources.