Explore core concepts of building REST APIs with Deno through this quiz designed for beginners. Assess your understanding of routing, request handling, HTTP methods, and other essential RESTful API techniques in a Deno environment.
Which code snippet properly starts an HTTP server in Deno that listens on port 8000?
Explanation: The correct method to start an HTTP server in Deno is using 'serve({ port: 8000 }, handler)'. The other options use incorrect function names or parameter formats. 'listenAndServe' and 'startServer' are not default Deno server methods, and 'createServer' is not part of Deno's native HTTP handling. Using the right method ensures your server boots correctly.
When accepting new user registrations via a REST API built with Deno, which HTTP method should you use?
Explanation: POST is the standard method for creating new resources, such as registering a new user. GET retrieves data, PUT generally updates existing resources, and DELETE is used for deletion. Using the POST method is best practice for submissions where new data is generated.
You need to retrieve details of a specific product with ID 42 via your Deno API. Which route should you define?
Explanation: The RESTful convention is to use '/products/42' to represent accessing the product with ID 42. '/product/42' is not plural and may not follow typical REST conventions; '/product?id=42' and '/products?id=42' use query parameters, which is less preferred for resource identification in REST paths.
Which built-in method helps you parse the JSON body from an incoming HTTP request in Deno?
Explanation: 'await request.json()' correctly parses the request's body as JSON in Deno. 'request.bodyJSON()' and 'JSON.parse(request)' are invalid in this context. 'await request.text()' retrieves raw text but does not parse it as JSON.
To indicate JSON data in your response, which header and value should you set?
Explanation: The 'Content-Type: application/json' header correctly signals JSON output. 'Content-Type: text/plain' is for plain text, 'Accept: application/json' goes in the request to specify what formats are accepted, and 'Data-Type: json' is not a standard HTTP header.
According to RESTful best practices, what should the endpoint be called when managing multiple orders in your Deno API?
Explanation: Plural nouns like '/orders' are the convention for endpoints representing collections of resources. '/order' is singular, '/manageOrders' uses a verb unnecessarily, and '/all_orders' adds redundant context.
If a client requests an undefined route in your Deno-powered REST API, which status code should you return?
Explanation: The 404 status code indicates 'Not Found', suitable for unknown routes. 500 implies server errors, 200 means success, and 302 indicates a redirect rather than a missing resource.
What header must you add to your REST API's responses to enable cross-origin requests from browsers?
Explanation: 'Access-Control-Allow-Origin' enables cross-origin requests. 'Access-Control-Request-Method' is used in preflight requests from clients, not as a response header. 'X-Requested-With' is a common custom request header. 'Allow-Origin-Cross' is not standard.
Which HTTP method should you use to update the details of an existing blog post in a Deno REST API?
Explanation: PUT is typically used for updating existing resources in REST APIs. GET only retrieves data, POST creates new resources, and FETCH is not an HTTP method.
What is the most common top-level structure for a successful JSON response from a REST API?
Explanation: '{ 'data': ... }' is a widely accepted convention for wrapping the result in APIs. '{ 'success': ... }' is often used as a flag instead of a wrapper, '{ 'error': ... }' is reserved for failures, and '{ 'result': ... }' is less common though sometimes used.