Full Stack

TypeScript / Python API Tutorial: Five Frameworks, One CRUD API

A hands-on tutorial that builds the same CRUD API five times — with Next.js, Express, NestJS, Flask, and FastAPI — so you can compare routing styles, validation, and architecture side by side.

10 min read
Published

Get the Full Source Code on GitHub

This article is a summary. The full, runnable tutorial — five complete framework implementations of the same CRUD API, plus a shared Next.js UI and per-framework docs — lives in the audoir/ts-python-api-tutorial repository.

View the Repository on GitHub

Introduction

There is no single "right" framework for building REST APIs — Next.js, Express, NestJS, Flask, and FastAPI each represent a different philosophy, from minimal flexibility to structured, opinionated architecture. The best way to understand the trade-offs is to build the same API five times and compare.

The ts-python-api-tutorial repository does exactly that: a simple CRUD API implemented in five popular frameworks, each in its own sub-folder, demonstrated through a shared Next.js UI. This post summarizes the framework comparison and what each tab covers — head to the repo for the full, runnable code and per-framework docs.

Framework Comparison

Not sure which framework to reach for? Here is a quick reference comparing all five at a glance.

FrameworkLanguageRoutingValidationBest For
Next.jsTypeScriptFile-system (app/api/route.ts)ZodFull-stack web apps
ExpressTypeScriptImperative (app.get(...))ZodSimple APIs, microservices, prototypes
NestJSTypeScriptDecorators (@Get())ZodLarge, structured backend APIs
FlaskPythonDecorators (@app.route(...))PydanticPython APIs, data science backends
FastAPIPythonDecorators (@app.get(...))Pydantic (built-in)High-performance Python APIs, ML serving

Six Tabs, Six Implementations

Each tab builds the exact same REST API contract — the same URLs, methods, and JSON shapes — so you can see how each framework approaches the identical problem.

Tab 1 · Port 3000

🟦 Next.js CRUD

A full-stack React framework with file-system routing — route.ts files under app/api/ become HTTP endpoints, validated with Zod.

Tab 2 · Port 3001

🟩 Express CRUD

The minimal, unopinionated Node.js web framework. Routes are declared imperatively with calls like app.get(...) — a blank canvas with no enforced structure.

Tab 3 · Port 3002

🐦 NestJS CRUD

Built on Express but adds an Angular-inspired architectural layer — decorators, dependency injection, and modules — that enforces conventions for large codebases.

Tab 4 · Port 3002

🚀 Advanced NestJS

Builds on Tab 3 with four real-world patterns served under /api/advanced: a @Public() custom decorator, an ApiKeyGuard, a response-wrapping interceptor, and constructor-based dependency injection.

Tab 5 · Port 3003

🐍 Flask CRUD

A minimal, synchronous (WSGI) Python framework using decorator-based routing and Pydantic for request validation.

Tab 6 · Port 3004

⚡ FastAPI CRUD

The same API as the Flask tab, rebuilt on the async-first (ASGI) FastAPI framework with built-in Pydantic validation and auto-generated Swagger/ReDoc documentation.

📚 Core Concepts Reference

New to web APIs? The repo's docs/concepts.md explains the foundational ideas that appear across all five frameworks — HTTP and REST, CRUD, middleware, routing, validation (Zod vs. Pydantic), dependency injection, decorators, CORS, WSGI vs. ASGI, sync vs. async, and OpenAPI/Swagger. If you hit an unfamiliar term in any tab, that's the place to look it up.

Getting Started

Clone the repo, then install dependencies per framework — Node.js frameworks use npm install, Flask's virtual environment is created automatically by uv on first run, and FastAPI uses uv sync.

From the repo root, run ./scripts/start-servers.sh to launch every tutorial server in the background at once (killed together with Ctrl-C), or start each framework individually — Next.js on :3000, Express on :3001, NestJS on :3002, Flask on :3003, and FastAPI on :3004. FastAPI also exposes interactive docs at /docs (Swagger) and /redoc. See the repository README for exact commands.

Conclusion

There is no single "right" framework for building REST APIs. Each of the five frameworks covered here represents a different philosophy — from the minimal flexibility of Express and Flask, to the structured power of NestJS, to the full-stack convenience of Next.js, to the async-first performance of FastAPI.

The key insight is that the concepts of web APIs are universal — routing, validation, middleware, error handling — only the syntax and conventions change. Building the same CRUD API in all five frameworks side by side shows exactly where each framework adds value and where it adds complexity.

Ready to Build It Yourself?

Clone the repository and run all five servers side by side to compare Next.js, Express, NestJS, Flask, and FastAPI in action.

Clone ts-python-api-tutorial on GitHub

About the Author

Wayne Cheng is the founder and AI app developer at Audoir, LLC. Prior to founding Audoir, he worked as a hardware design engineer for Silicon Valley startups and an audio engineer for creative organizations. He holds an MSEE from UC Davis and a Music Technology degree from Foothill College.

Further Exploration

Explore the ts-python-api-tutorial repository and experiment with extending the examples. Consider replacing the in-memory store with a real database, adding authentication, or deploying one of the backends to a cloud provider to deepen your understanding of API development.

For more AI-powered development tools and tutorials, visit Audoir .