Week 1
Week 1
Join the github classroom assignment with the following link: https://classroom.github.com/a/KOc7f0j5
Once you join your repository will be created https://github.com/blueprint-learn/week1-techteam-sp26-{github-username}
You will get an email with access to your repo
Clone your repo
git clone https://github.com/blueprint-learn/week1-techteam-sp26-{github-username}.git
Goal for today
By the end of this class, you will understand what an API is and you will have written and run a real backend service.
Set expectations
-
This is not web dev with HTML
-
This is backend infrastructure
-
What we build today looks simple, but it’s the same pattern used by Netflix, Stripe, AWS, etc.
1. What Is an API?
Core idea
-
API = contract between a client and a server
-
You ask for data → server responds with data
Client (browser / app / script)
|
| HTTP request
v
API Server
|
| JSON response
v
Client
Key clarification
-
APIs don’t care who the client is
-
Browser, mobile app, another server — all the same
Examples
-
Instagram feed
-
Spotify playlists
-
Google Maps directions
2. REST & HTTP Basics
REST (high-level)
-
Everything is a resource
-
Each resource has a URL
HTTP Methods
|
Method |
Meaning |
|---|---|
|
GET |
Read data |
|
POST |
Create data |
|
PUT |
Update data |
|
DELETE |
Remove data |
HTTP Response
-
Status code (200, 404, etc.)
-
Body (usually JSON)
{
"id": 3,
"name": "Notebook",
"price": 5.99
}
Important
-
JSON ≠ Python dictionary (but very similar)
3. Live Demo Setup
pip3 install -r requirements.txt
Minimal app
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def root():
return {"message": "Hello World"}
Run the app
uvicorn app.main:app --reload
4. Endpoints & Path Parameters
@app.get("/items/{item_id}")
def read_item(item_id: int):
return {"item_id": item_id}
- Automatic validation
- Type validation
No Comments