or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-9/

Resource Metadata API

Build a lightweight API server that provides metadata about resources. The server should handle requests to check if resources exist and return appropriate information.

Requirements

Create a Koa application with the following routes:

  1. A route that handles requests to /api/resources/:id and returns metadata about a resource with the given ID
  2. The route should return a JSON response with the resource metadata when the full resource data is requested
  3. The route should also support requests that only check if the resource exists without retrieving the full data

Expected Behavior

  • When a request is made to retrieve resource metadata (e.g., /api/resources/123), the server should return a JSON response with resource details including an id field and a name field
  • When a request is made to only check if a resource exists, the server should return appropriate headers indicating the resource is available, but without sending the full response body
  • The server should handle both types of requests using the same route definition
  • For testing purposes, assume resources with IDs "123", "456", and "789" exist with names "Resource A", "Resource B", and "Resource C" respectively
  • For any other resource ID, return a 404 status with an error message

Implementation

@generates

API

/**
 * Creates and configures a Koa application with resource routes.
 *
 * @returns {Object} A configured Koa application instance
 */
function createApp() {
  // IMPLEMENTATION HERE
}

module.exports = { createApp };

Test Cases

  • Requesting metadata for resource "123" returns a JSON response with {"id": "123", "name": "Resource A"} @test
  • Checking if resource "456" exists returns a successful response with appropriate headers but no body @test
  • Requesting metadata for a non-existent resource "999" returns a 404 status @test

Dependencies { .dependencies }

Koa { .dependency }

Provides the web application framework for building the API server.

@satisfied-by

koa-route { .dependency }

Provides routing middleware for handling different API endpoints.

@satisfied-by