Help us measure site usage?

With your permission, we use self-hosted analytics to understand page usage. It is optional and does not affect the Service. Learn more.

ScalaintermediatebackendAI generated

Task Manager REST API with Akka HTTP

Build a REST API for managing tasks in Scala with Akka HTTP: create tasks with a title, description, priority and due date, list them with filters, update them, mark them complete, and delete them, with JSON handled by spray-json and data stored in an embedded H2 database. Input is validated and errors come back in one clear format, and every route is tested with Akka HTTP's route testkit. (Note that newer Akka versions use a commercial license; Apache Pekko HTTP is a free, compatible alternative with the same API.) You'll learn Akka HTTP's routing DSL, JSON marshalling, modeling a domain with case classes, database access with JDBC or a library such as Slick, validation, and testing routes.

Estimate
~10.5h
Steps
6
Completed by
0
Proposed by
codeseed.app

Akka/Pekko HTTP · spray-json · H2

Project roadmap

  1. 01

    Start the server

    ~1.5h

    Create an sbt project with Akka HTTP (or Pekko HTTP), spray-json and H2. Start an HTTP server on a configurable port with an actor system, a GET /health route, and clean shutdown. Done when: curl localhost:8080/health returns OK.

  2. 02

    Model tasks and JSON

    ~1.5h

    Define case classes Task (id, title, description, priority as an enum, due date, completed, created at) and request types CreateTask and UpdateTask. Write spray-json formats for them, including the enum and dates (ISO format). Done when: tasks convert to and from JSON correctly in a unit test.

  3. 03

    Store tasks in H2

    ~2h

    Create a TaskRepository trait and an H2 implementation (with Slick, or plain JDBC with prepared statements), creating the table at startup. Run database calls on a separate dispatcher (or wrap them in Futures on a dedicated execution context) so they don't block the HTTP threads. Done when: repository methods save, find, update and delete tasks in a test.

  4. 04

    Build the routes

    ~2h

    Build routes with the routing DSL: GET /tasks (with ?completed=, ?priority= and ?dueBefore= filters, and sorting by due date), GET /tasks/{id}, POST /tasks, PUT /tasks/{id}, POST /tasks/{id}/complete and DELETE /tasks/{id}. Return 201 with a Location header on create, 404 for unknown ids and 204 on delete. Done when: every route works with curl.

  5. 05

    Validate input

    ~1.5h

    Validate requests: the title is 1 to 200 characters, the priority is a known value, and the due date is a valid date not in the past for new tasks. Return 400 with a JSON list of errors. Add a rejection and exception handler so malformed JSON and unexpected errors also return JSON errors instead of plain text. Done when: every kind of bad input returns a clear JSON error.

  6. 06

    Test the routes

    ~2h

    Write tests with ScalatestRouteTest (the route testkit) using an in-memory repository: every endpoint's success case, filters and sorting, 404s, validation errors and malformed JSON. Add one test with the real H2 repository. Done when: sbt test passes.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~10.5h · 6 steps

Tech stack

Akka/Pekko HTTPspray-jsonH2