Skip to content

maxrosen/task-api-challenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task Manager API — Coding Challenge

Welcome! You've inherited a small REST API for managing tasks, written by another developer. QA has filed a few bug reports, and product has requested a new endpoint. Your job is to ship the fixes and the new feature.

Time: 45 minutes Stack: Node.js, Express, SQLite (in-memory)


Getting started

  1. From this repo on GitHub, click the green Code button → Codespaces tab → Create codespace on main.
  2. Wait about 45 seconds while the environment boots and dependencies install automatically.
  3. In the Codespace terminal, run:
    npm start
  4. A notification will appear that port 3000 has been forwarded. You can either open the forwarded URL in a new browser tab, or test the API directly from the same Codespace terminal with curl (examples below).

The API

A task has this shape:

{
  "id": 1,
  "title": "Buy groceries",
  "description": "Milk, eggs, bread",
  "completed": 0,
  "created_at": "2026-05-22 14:30:00"
}

Existing endpoints:

Method Path Description
GET /tasks List all tasks. Optional ?completed=true or false
GET /tasks/:id Get a single task
POST /tasks Create a task. Body: { "title": "...", "description": "..." }. Title required.
PATCH /tasks/:id Update any subset of fields
DELETE /tasks/:id Delete a task

Part 1 — Fix the bugs (~30 min)

QA has reported three issues. Reproduce each one, then fix it.

  1. Filtering doesn't work. GET /tasks?completed=true returns an empty array even though some tasks are clearly completed.
  2. Missing tasks return 200. GET /tasks/9999 (a non-existent id) returns 200 OK with an empty body. It should return 404 Not Found.
  3. Bad input crashes the server. POST /tasks with no title returns a 500 Internal Server Error. It should return 400 Bad Request with a helpful error message.

Part 2 — Add a priority field and an endpoint to use it (~15 min)

Product wants every task to have a priority level. Implement this in three steps:

  1. Update the schema. Add a priority column to the tasks table. It must be one of "low", "medium", or "high", and default to "medium" when not provided. The existing seed data should still load without errors.
  2. Accept it on create. Update POST /tasks so callers can optionally include a priority field in the request body. Reject invalid values with 400 Bad Request.
  3. Add a new endpoint. GET /tasks/by-priority/:level should return all tasks at that priority level. Return 400 Bad Request if :level isn't one of the three valid values.

How to test your work

Open the Shell tab in Replit (or a second terminal) and use curl:

# List all tasks
curl http://localhost:3000/tasks

# Filter — should return only completed
curl "http://localhost:3000/tasks?completed=true"

# Get one
curl http://localhost:3000/tasks/1

# Get a missing one — should be 404
curl -i http://localhost:3000/tasks/9999

# Create
curl -X POST -H "Content-Type: application/json" \
  -d '{"title":"New task","description":"Notes"}' \
  http://localhost:3000/tasks

# Create with missing title — should be 400
curl -i -X POST -H "Content-Type: application/json" \
  -d '{}' http://localhost:3000/tasks

# Create with a priority
curl -X POST -H "Content-Type: application/json" \
  -d '{"title":"Urgent task","priority":"high"}' \
  http://localhost:3000/tasks

# Create with an invalid priority — should be 400
curl -i -X POST -H "Content-Type: application/json" \
  -d '{"title":"Bad","priority":"urgent"}' \
  http://localhost:3000/tasks

# List by priority (your new endpoint)
curl http://localhost:3000/tasks/by-priority/high

# Invalid priority level — should be 400
curl -i http://localhost:3000/tasks/by-priority/urgent

The -i flag prints the HTTP status, which is helpful for verifying 404 / 400 responses.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors