docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a Koa.js application that implements flexible path matching for API endpoints under different version namespaces.
Your application should implement the following routing behavior:
Create routes that match all paths starting with a specific prefix. The routes should match any path that continues beyond the prefix:
/api/v1/users should match and capture the remaining path/api/v1/products/123 should match and capture the remaining path/api/v2/orders should match (for v2 routes) and capture the remaining pathFor each API version route, capture the remaining path after the version prefix and return it in the response. The response body should be a JSON object with:
version: The API version (e.g., "v1" or "v2")path: The captured remaining path (e.g., "/users" or "/products/123")Implement separate route handlers for v1 and v2 API versions that process requests to their respective prefixes.
GET /api/v1/users returns JSON {"version":"v1","path":"/users"} @testGET /api/v1/products/123 returns JSON {"version":"v1","path":"/products/123"} @testGET /api/v2/orders returns JSON {"version":"v2","path":"/orders"} @test// Create and export a configured Koa application with the routing behavior described above
const app = require('koa')();
// Add your routing logic here
module.exports = app;Provides web application framework.
Provides route middleware with advanced path matching capabilities.