or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-2/

Task Management API

Build a simple task management API using Koa that handles CRUD operations for tasks. The API should support multiple HTTP methods to manage a collection of tasks.

Requirements

Implement an API server with the following endpoints:

  1. GET /tasks - Returns a list of all tasks as JSON
  2. GET /tasks/:id - Returns a specific task by ID as JSON
  3. POST /tasks - Creates a new task from the request body and returns the created task
  4. PUT /tasks/:id - Updates an existing task by ID and returns the updated task
  5. DELETE /tasks/:id - Deletes a task by ID and returns a success message

Each task should have:

  • id (string): A unique identifier
  • title (string): The task title
  • completed (boolean): Whether the task is completed

Implementation Details

  • Use an in-memory data structure to store tasks
  • For POST and PUT requests, parse the JSON request body using ctx.request.body
  • Return appropriate JSON responses for all endpoints
  • Set ctx.status appropriately for each operation
  • For GET /tasks/:id, PUT /tasks/:id, and DELETE /tasks/:id, return 404 status if the task is not found

Test Cases

  • GET /tasks returns an array of tasks @test
  • GET /tasks/:id returns the correct task for a valid ID @test
  • GET /tasks/:id returns 404 for a non-existent ID @test
  • POST /tasks creates a new task and returns it with status 201 @test
  • PUT /tasks/:id updates an existing task and returns the updated task @test
  • DELETE /tasks/:id deletes a task and returns status 200 @test

Implementation

@generates

API

/**
 * Creates and configures a Koa application with task management routes
 * @returns {Koa} The configured Koa application
 */
function createApp() {
  // Implementation here
}

module.exports = { createApp };

Dependencies { .dependencies }

koa-route { .dependency }

Provides HTTP method-based routing for the Koa application.

koa { .dependency }

Web framework for Node.js.

koa-bodyparser { .dependency }

Middleware for parsing JSON request bodies.