Complete the code to create a basic GET route using Oak framework.
router.[1]('/home', (context) => { context.response.body = 'Welcome Home'; });
The get method defines a route that responds to GET requests.
Complete the code to extract a route parameter named 'id'.
router.get('/user/:[1]', (context) => { const id = context.params.id; context.response.body = `User ID is ${id}`; });
The route parameter :id matches the URL segment and is accessed via context.params.id.
Fix the error in the middleware function to correctly pass control to the next handler.
router.get('/data', async (context, [1]) => { context.response.body = 'Data loaded'; await next(); });
await next() to continue middleware chainThe second parameter is conventionally named next and is used to call the next middleware.
Fill both blanks to create a route that matches any HTTP method and responds with 'Hello'.
router.[1]('/hello', (context) => { context.response.body = '[2]'; });
The all method matches all HTTP methods. The response body is set to 'Hello'.
Fill all three blanks to create a nested router with prefix '/api' and a GET route '/status' that returns JSON.
const apiRouter = new Router().[1]('/api'); apiRouter.[2]('/status', (context) => { context.response.body = { [3]: 'ok' }; });
The prefix method sets the base path for the router. The get method defines a GET route. The JSON key must be a string, so "status" is correct.
