docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a simple Koa application that serves resource data with optional filtering capabilities through URL parameters.
Create a Koa web server with the following endpoints:
Create an endpoint that handles requests to /api/resources and /api/resources/:category where:
Create an endpoint that handles requests to /api/resources/:id/details and /api/resources/:id/details/:format where:
:id is required and represents the resource ID:format is optional and can be either "json" or "xml"{"id": <id>, "format": "json"}{"id": <id>, "format": "xml"}Use this sample data for resources:
const resources = [
{ id: 1, name: "Resource A", category: "books" },
{ id: 2, name: "Resource B", category: "movies" },
{ id: 3, name: "Resource C", category: "books" }
];/api/resources returns all 3 resources with status 200 @test/api/resources/books returns only resources with category "books" @test/api/resources/movies returns only resources with category "movies" @test/api/resources/:id/details with id=1 returns JSON format by default @test/api/resources/:id/details/xml with id=2 returns XML format @test// Main Koa application
const Koa = require('koa');
const app = new Koa();
// Configure routes and start serverWeb framework for Node.js providing context-based request handling.
Provides route middleware with path parameter support.