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 URL shortener API service that handles different path patterns for creating, retrieving, and managing shortened URLs.
Create a Koa application with the following routes:
Create Short URL: Accept POST requests to create a new shortened URL
/shorten{ "url": "https://example.com" }{ "short": "abc123" } with status 201Redirect to Original URL: Accept GET requests with a short code to redirect
/r/:codeGet User URLs: Accept GET requests to list URLs created by a user
/user/:username{ "username": "john", "urls": [{"short": "abc123", "url": "..."}] } with status 200Get URL Details: Accept GET requests with optional code parameter
/details/:username/:code?code is provided, returns detailed info for that URL: { "short": "abc123", "url": "...", "clicks": 5 }code is not provided, returns summary: { "username": "john", "totalUrls": 3, "totalClicks": 15 }For the purposes of this exercise:
// Create and configure the Koa application with all routes
function createApp() {
// Returns configured Koa app instance
}
module.exports = { createApp };/shorten with {"url": "https://example.com", "username": "john"} returns status 201 with {"short": "..."} @test/r/abc123 (existing code) redirects with status 302 to the original URL and increments click count @test/r/missing (non-existent code) returns status 404 @test/user/john returns status 200 with array of URLs created by user "john" @test/user/jane%20doe (URL-encoded username with space) correctly decodes to "jane doe" and returns their URLs @test/details/john/abc123 returns status 200 with detailed info including click count for that specific URL @test/details/john (without code parameter) returns status 200 with summary statistics for user "john" @test/details/alice%20smith/xyz789 correctly decodes username "alice smith" and code "xyz789" @testProvides the web application framework.
Provides routing middleware with path parameter support.
Provides request body parsing for POST requests.