Software components for beginners
Session 1 asks you to ship a real service: something other programs can call over the network. That service sits on top of several ordinary software components. This page names them, says what each one is for, and shows how they fit together when you build `POST /ask`.
Tip
How to use this page
Skim once now. Come back when a live demo mentions a term you do not recognise. You do not need mastery. You need a picture of the machine you are building.
1. The big picture: client, server, and a contract
Almost every web system has two sides. A client asks for something (your browser, `curl`, Streamlit, another service). A server answers. The contract between them is the API: which URLs exist, what you send, and what you get back.
Client
The caller. In Week 1 that is often `curl` or a small Streamlit UI. Later it can be another agent or product.
Server
Your FastAPI app. It listens on a port, receives requests, calls OpenAI when needed, and returns a response.
Contract (API)
Agreed shapes: path (`/ask`), method (`POST`), JSON body, and JSON response. If either side breaks the contract, the system fails in predictable ways.
2. What is an API?
An API (Application Programming Interface) is how one piece of software talks to another without knowing its internals. You do not open the OpenAI model weights. You call their API. Other apps will not open your Python files. They will call your API.
In this bootcamp you are on both sides: you consume the OpenAI API, and you expose your own API so a UI or another service can ask questions of your system.
3. What is a REST API?
REST is a common style for HTTP APIs. In practice for this course it means: resources live at URLs (paths), you use standard HTTP methods, you usually send and receive JSON, and each request stands alone (the server does not need a sticky chat session to understand `POST /ask`).
- Resource / path - a URL path that names the action or thing, e.g. `/ask` or `/health`.
- Method - what kind of action: read, create, update, delete.
- Headers - metadata (auth keys, content type).
- Body - the payload for writes (JSON for us).
- Status code - short machine-readable outcome: 200 ok, 400 bad input, 500 server error.
4. HTTP methods you will actually use
GET
ReadRead something. Safe and repeatable. Example: `GET /health` returns `{ "status": "ok" }` so a host knows you are alive.
POST
Write / runSend data to create or run something. Example: `POST /ask` with `{ "question": "..." }` runs your model call and returns an answer.
PUT / PATCH / DELETE
LaterUpdate or remove resources. You may not need them in Week 1. Know they exist when you add ingest, memory, or admin routes later.
Example
Why Week 1 is a POST
Asking a question has a body (the question) and side effects (tokens spent, a model call). That is a POST, not a GET. GET is for cheap, cacheable reads like health checks.
5. Request and response (the round trip)
- 1
Client builds a request
Method + URL + headers + optional JSON body. Example: POST to `https://your-app.onrender.com/ask` with `{ "question": "What is RAG?" }`.
- 2
Server handles it
FastAPI matches the route, validates the body with Pydantic, runs your code (including the OpenAI call), and builds a response.
- 3
Client reads the response
Status code plus JSON body. Success might be 200 with `{ "answer": "...", "confidence": 0.9 }`. Bad input might be 422 with a validation error.
Status codes worth memorising: 200 (ok), 201 (created), 400/422 (your request was wrong), 401/403 (auth), 404 (unknown path), 429 (rate limited), 500 (server broke - avoid returning this bare to users when you can return a safe fallback instead).
6. JSON: the lingua franca
JSON is a text format for structured data: objects `{ }`, arrays `[ ]`, strings, numbers, booleans, null. APIs use it because every language can parse it. Your Pydantic models are the typed Python view of those JSON shapes.
{
"question": "What is an API?"
}7. FastAPI: your server framework
FastAPI is a Python framework for building HTTP APIs quickly. We use it because:
- You declare request and response shapes with Pydantic. Invalid input is rejected before your model call.
- It is async-friendly and fast enough for real products.
- It auto-generates interactive docs (`/docs`) so you can click and try endpoints.
- It is the de facto default for Python AI backends in 2026.
Mental model: FastAPI is the receptionist. It greets HTTP, checks the form (schema), hands work to your functions, and sends the reply back in the right envelope.
8. Endpoints, routes, and handlers
- Route / endpoint - the path + method pair, e.g. `POST /ask`.
- Handler - the Python function that runs when that route is hit.
- Dependency - shared setup (read the API key, open a DB) injected into handlers.
Week 1 deliverable in one sentence: a handler behind `POST /ask` that validates input, calls a model reliably, and returns a structured answer.
9. Environment variables and secrets
Your OpenAI key must never live in GitHub. It lives in the environment: a `.env` file locally (gitignored), and host settings on Render/Railway/Fly. Code reads `os.getenv("OPENAI_API_KEY")`. Same pattern for every secret.
10. Docker: same machine everywhere
A container packages your app and its dependencies so it runs the same on your laptop and in the cloud. Docker is the tool that builds and runs those containers from a `Dockerfile`.
Image
The recipe baked into a snapshot: Python, your code, installed packages. Built once, run many times.
Container
A running instance of that image. Stop it, start another, scale to many.
Why it matters
"Works on my machine" becomes "works in this image." Hosts like Render run your container and give you a public URL.
11. Deploy: from laptop to URL
Deploy means putting the running server on a host the internet can reach. Week 1: push a container (or connected repo), set env vars, get `https://….onrender.com`. That URL is what you curl, share, and later point a UI at.
12. Vertical vs horizontal scaling
When traffic grows, you scale in two different ways. Both show up in production AI systems (more users, more model calls, more latency pressure).
Vertical scaling (scale up)
Bigger boxGive one machine more CPU, RAM, or a bigger GPU. Simple at first. Hits a ceiling. One box is still one failure domain.
Horizontal scaling (scale out)
More copiesRun many copies of the same container behind a load balancer. Add or remove copies as load changes. This is how most web APIs grow.
Tip
For Session 1
One container on a free or starter host is enough. Learn the words now so Week 4 and production talks are not foreign. Stateless POST /ask (no sticky session required) is what makes horizontal scaling straightforward later.
13. Related pieces you will hear soon
Load balancer
Sits in front of many app copies and spreads requests across them.
Database
Where durable state lives (users, tickets, vectors). Week 1 can be mostly stateless; RAG and memory bring storage back in.
Auth
Who is allowed to call you. API keys, JWTs, login. Protect paid or private endpoints.
Logs and observability
What happened on each request: latency, errors, token cost. You cannot improve what you cannot see.
CI/CD
Automated tests and deploys on every push. Your eval suite eventually belongs here.
Reverse proxy / TLS
Hosts terminate HTTPS and forward traffic to your container. You usually get this for free on managed platforms.
14. Put it together: the Week 1 machine
- 1
Client sends POST /ask
JSON body with a question.
- 2
FastAPI validates and handles
Pydantic checks the shape. Your harness calls OpenAI with timeouts and retries.
- 3
Structured Answer returns
JSON the client can trust. On failure, a safe Answer shape beats a bare 500.
- 4
Docker + host expose a URL
Same image locally and in the cloud. Env vars hold the key. Scaling comes later.
Ready when
Next
If this map makes sense, continue pre-course setup (coding agent, Python, key, capstone seed). When Session 1 hits the Playground, open the Prompting lab for copy-paste weak vs strong demos: `/ai-eng-syllabus/prompting-lab`.
Done when
- You can explain client vs server vs API in one breath
- You know why Week 1 uses POST /ask and what JSON is for
- You can say what FastAPI and Docker each contribute
- You can contrast vertical and horizontal scaling in plain language