Lesson 1 - What FastAPI Is and Why It's Fast
On this page
Welcome to What FastAPI Is
Every app you use talks to a server somewhere: your phone asks “what are my tasks?” and something answers with data. That something is an API — a program that listens for requests over the web and sends back answers. FastAPI is a Python framework for building exactly that, and it has become the most popular modern choice because it asks so little of you and gives so much back. You write a normal Python function with type hints, and FastAPI turns it into a working web endpoint — with input validation, JSON responses, and live interactive documentation, all generated for you.
This first lesson is about the big picture: what FastAPI is, why people reach for it, and the one idea that makes it click. You won’t install anything yet — that’s Lesson 2.
By the end of this lesson, you will be able to:
- Explain what an API is and what a web framework does
- Describe what makes FastAPI fast and beginner-friendly
- Explain how Python type hints drive FastAPI
- Name the three things FastAPI generates from a single function
Let’s begin.
What Is an API?
An API (Application Programming Interface) is a program that other programs talk to. On the web, that conversation is made of requests and responses: a client (a browser, a mobile app, another server) sends a request like “GET me the task with id 3,” and your API sends back a response — usually JSON, a simple text format for structured data.
A single API is made of endpoints — specific URLs that do specific things. GET /tasks might list all tasks; GET /tasks/3 might return just task 3. Each endpoint is a small, focused job. Your work as an API developer is to write the code behind each one: receive the request, do something useful, and return an answer.
A web framework like FastAPI handles the tedious parts of that — listening for requests, matching URLs to your code, reading the incoming data, and formatting the response — so you can focus on the useful part: what each endpoint actually does.
Why FastAPI?
There are several Python web frameworks (you may have heard of Flask or Django). FastAPI stands out for three reasons, and all three matter to a beginner:
- It’s fast — to run and to write. FastAPI is built on modern asynchronous Python, so it’s among the fastest Python frameworks available. But “fast” also means fast to build with: most endpoints are just a few lines.
- It validates your data automatically. You declare what an endpoint expects using ordinary Python type hints, and FastAPI checks every incoming request against them — rejecting bad input with a clear error before your code ever runs.
- It documents itself. From those same type hints, FastAPI generates a live, interactive documentation page where anyone can see your endpoints and try them in the browser. You write zero documentation code.
That last two points come from a single design choice: FastAPI is type-driven. The type hints you’d write anyway become the source of truth for validation and docs.
The Big Idea: One Typed Function
Here is the whole philosophy in one example. This is a complete FastAPI endpoint (you’ll run code like it in Lesson 2):
from fastapi import FastAPI
app = FastAPI()
@app.get("/tasks/{task_id}")
def read_task(task_id: int):
return {"task_id": task_id, "title": "Write the report"}Look at how little is here, and how much it declares. The @app.get("/tasks/{task_id}") line says “when a client sends a GET request to this URL, run this function.” The task_id: int type hint says “this part of the URL is an integer.” The function returns a plain Python dictionary. From just this, FastAPI does three things for you automatically:
- Validation — because you said
task_id: int, a request to/tasks/3works, but/tasks/bananais rejected with a clear error. You wrote no validation code. - A JSON response — the dictionary you returned is automatically converted to JSON with the right headers. Clients get clean, structured data.
- Interactive docs — FastAPI builds a
/docspage listing this endpoint, showing that it needs an integertask_id, and letting anyone try it live in the browser.
One function in; validation, JSON, and documentation out. That’s the trade that makes FastAPI feel almost unfair — and it’s why the rest of this course will feel less like fighting a framework and more like writing plain Python.
Type hints are the secret
If you’ve seen Python type hints like task_id: int before and wondered whether they actually do anything at runtime — in most Python they don’t. FastAPI is different: it reads those hints and acts on them, using them to parse input, validate it, and describe your API. Learning FastAPI is largely learning to express what you want through types.
What You’ll Build
This course is built around one project that grows with you: a Task Manager API. You’ll start this module by serving a fixed list of tasks (read-only), then over the coming modules add the ability to create and edit tasks with validation, store them in a real database, protect them behind a login, test the whole thing, and finally deploy it. By treating it as one evolving project, every new concept attaches to something you already understand instead of starting from a blank page each time.
By the end you’ll have a complete, deployable REST API — and the skills to build one for any idea you have.
Practice Exercises
Exercise 1: Spot the endpoints
For a Task Manager API, write out the URL and method (GET/POST) you’d expect for: (a) listing all tasks, (b) getting one task by its id, (c) creating a new task. You don’t need code — just the endpoint shapes.
Hint
Reading uses GET; creating uses POST. So: (a) GET /tasks, (b) GET /tasks/{task_id}, (c) POST /tasks. The {task_id} part is a path parameter — you’ll learn those in Lesson 3.
Exercise 2: Predict the validation
Given the endpoint def read_task(task_id: int), which of these requests succeed and which are rejected: /tasks/7, /tasks/0, /tasks/seven? Why?
Hint
/tasks/7 and /tasks/0 succeed — both are integers. /tasks/seven is rejected, because “seven” can’t be parsed as an int. FastAPI checks this for you, before your function runs, and returns a clear error.
Exercise 3: What comes for free?
A teammate says “we’ll need to write documentation for the API and add code to reject bad input.” Based on this lesson, what can you tell them FastAPI already handles?
Hint
Both. FastAPI auto-generates interactive docs at /docs from your type hints, and it validates incoming data against those same hints — rejecting bad input automatically. Your team writes far less boilerplate than they expect.
Summary
An API answers requests over the web with data (usually JSON), and a web framework handles the plumbing so you can focus on what each endpoint does. FastAPI is the modern, beginner-friendly Python framework for building APIs: it’s fast to run and to write, and because it’s type-driven, the ordinary Python type hints you add become the source of truth for three things it generates automatically — validation, JSON responses, and interactive documentation. You write one small typed function; FastAPI does the rest.
Key Concepts
- API — a program that answers requests from other programs over the web.
- Endpoint — one URL + method that does one job (e.g.
GET /tasks/3). - Web framework — handles requests, routing, and responses for you.
- Type-driven — FastAPI reads your type hints to validate input and build docs.
- Three freebies — validation, JSON responses, and interactive docs from one function.
Why This Matters
APIs are how nearly all modern software communicates — web and mobile apps, microservices, and the AI services you might build later all expose APIs. FastAPI lets you build them with remarkably little code, which is why it’s a sought-after skill and the foundation for everything else in this course. Understanding the type-driven idea now means every later lesson — validation, databases, auth — will feel like a natural extension of the same simple pattern.
Next Steps
Continue to Lesson 2 - Your First API
Install FastAPI, write and run your first app with uvicorn, and explore the automatic interactive docs.
Back to Module Overview
Return to the Getting Started with FastAPI module overview
Continue Building Your Skills
You now know what FastAPI is and the one idea that powers it: typed functions become full endpoints. Next you’ll make it real — install FastAPI, run your first app, and open the interactive docs page that FastAPI builds for you.