or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-4/

Task: Blog Post API with Parameterized Routes

Build a simple blog API that uses route parameters to handle requests for viewing blog posts and user profiles.

Requirements

Your API should handle the following routes:

  1. Get a specific blog post: GET /posts/:id

    • Should extract the post ID from the URL
    • Return a response with the post ID in the body
  2. Get posts by category: GET /category/:categoryName/posts

    • Should extract the category name from the URL
    • Return a response indicating the category being requested
  3. Get a user profile: GET /users/:username

    • Should extract the username from the URL
    • Return a response with the username

All route handlers should:

  • Extract the appropriate parameter(s) from the URL path
  • Set the response status to 200
  • Return a JSON response containing the extracted parameter value(s)

Implementation Details

Create the following files:

app.js { .file }

This file should:

  • Create and configure a Koa application
  • Define all the required routes using parameterized paths
  • Export the Koa app instance (do not call app.listen())

app.test.js { .file }

This file should contain tests for the routes you created.

Dependencies { .dependencies }

koa { .dependency }

Web framework for Node.js.

koa-route { .dependency }

Simple route middleware for Koa applications.

supertest { .dependency }

HTTP assertion library for testing.

Test Cases

Test 1: Get specific post @test

Request:

GET /posts/42

Expected Response:

  • Status: 200
  • Body should contain: { "postId": "42" }

Test 2: Get posts by category @test

Request:

GET /category/technology/posts

Expected Response:

  • Status: 200
  • Body should contain: { "category": "technology" }

Test 3: Get user profile @test

Request:

GET /users/alice

Expected Response:

  • Status: 200
  • Body should contain: { "username": "alice" }