🐍 Python for Everyone

← Back to interview questions

Chapter 22 Project 65 min build

Task Manager REST API — Flask & FastAPI

A note on this project's file structure This chapter explicitly teaches two frameworks side by side, so this project deviates from the usual single-starter.py/solution.py convention on purpose: there are two parallel pairs of files — starter_flask.py/solution_flask.py and starter_fastapi.py/solution_fastapi.py. Both build the exact same task manager, so the contrast between the two frameworks stays concrete and side by side.

A Task Manager REST API — CRUD on an in-memory list of tasks — built once in Flask, once in FastAPI. The Flask version is a small JSON API plus one server-rendered HTML page at /, showing Flask's classic idiom clearly. The FastAPI version is a pure, typed JSON API using Pydantic models for validation, with no HTML page at all — matching FastAPI's idiom and this chapter's point that a JSON API is meant to be consumed by something else.

Example run

Output (Flask version)
=== Task Manager REST API -- Flask version ===
Demonstration (no live server, calling the same logic the routes use):
GET /api/tasks       -> [{'id': 1, 'title': 'Write the report', 'done': False}, {'id': 2, 'title': 'Review pull request', 'done': True}]
GET /api/tasks/1     -> {'id': 1, 'title': 'Write the report', 'done': False}
POST /api/tasks      -> {'id': 3, 'title': 'Water the plants', 'done': False}
PATCH /api/tasks/1   -> {'id': 1, 'title': 'Write the report', 'done': True}
DELETE /api/tasks/2  -> True
GET /api/tasks (after changes) -> [{'id': 1, 'title': 'Write the report', 'done': True}, {'id': 3, 'title': 'Water the plants', 'done': False}]
Why this project can't start a live server This course has no backend of its own and Pyodide's sandbox can't run a real Flask/FastAPI server. Every route below is written as real, complete Flask/FastAPI code (real decorators, a real Pydantic BaseModel, a commented-out app.run()/uvicorn.run() call), but each route is a thin wrapper around a plain Python function holding the actual logic — those functions are what run directly in this course, with the server call left for you to uncomment and run for real, locally, once Flask or FastAPI+uvicorn is installed.
How to run Download starter_flask.py and/or starter_fastapi.py below into an empty folder, then run python3 starter_flask.py (or starter_fastapi.py).

The pieces

Ideas to make it your own

Why this project matters

Nearly every mobile app backend and modern web application is, at its core, exactly this pattern: CRUD operations exposed over HTTP as a small set of routes. Building the same feature twice — once in Flask's simpler, HTML-first style and once in FastAPI's typed, JSON-first, auto-documented style — makes the Flask-vs-FastAPI tradeoff concrete instead of abstract.

More project ideas

From Chapter 7 onward, you get a genuine choice of what to build. The Task Manager REST API above is fully built out with starter and reference solution files for both frameworks — the four ideas below are not. Each is a real, grounded use case solvable with only what's been taught through Chapter 22. No starter or solution files are provided on purpose — building one of these unassisted is the point.

1 A Simple Blog API

Problem: A blogging platform needs a backend API for creating, listing, and reading blog posts.

What it should do: Build routes for listing posts, getting one post by ID, and creating a new post (title + body), using a Pydantic model (or Flask's request.json) for the create route. Store posts in an in-memory list.

Suggested approach: Reuse this project's exact CRUD-route structure, swapping "task" for "post" and adding a body field.

2 A URL Shortener API

Problem: A URL shortener needs an API that accepts a long URL and returns a short code, then looks that code back up to the original URL.

What it should do: Build a POST route generating a random short code (Chapter 11's random module) for a submitted URL, and a GET route /{short_code} looking it back up.

Suggested approach: A great fit for FastAPI's path parameters — /{short_code} is exactly Sub-topic 4's pattern.

3 A Bookmark Manager with Tags

Problem: A bookmark manager needs to store URLs tagged with categories, and support filtering by tag.

What it should do: Build CRUD routes for bookmarks (url, title, tags: list[str]), plus a filtering query parameter GET /bookmarks?tag=python.

Suggested approach: A Pydantic field can be typed tags: list[str] directly — FastAPI validates it the same way it validates any other typed field.

4 A Personal Expense Tracker API

Problem: Someone wants a small API to log personal expenses and see a running total.

What it should do: Build routes to add an expense (amount, category, optional note), list expenses (optionally filtered by category), and a GET /expenses/total route summing all amounts.

Suggested approach: Build this one in whichever framework you found more comfortable, going deeper in just one instead of splitting effort across both again.

← Interview Questions All Chapters →