← Back to FastAPI map
FastAPI · Reference

Cheatsheet

Commands to install and run, the route decorators, and the parameter types.

quick ref

Overview

A one-page reference for the commands and signatures used throughout the course. Use it to recall a signature quickly once the lessons are familiar - the reasoning behind each line is in the lesson that covers it.

Key concepts

Where values come from
Path -> Path(), query string -> Query(), headers -> Header(), cookies -> Cookie(), JSON -> a Pydantic model or Body(), forms -> Form(), files -> File() / UploadFile.
Status codes
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized (not authenticated), 403 Forbidden, 404 Not Found, 422 validation error.

Quick reference

Install & run

CLI
Commands
pip install "fastapi[standard]"Install FastAPI with all extras
uvicorn main:app --reloadDev server with auto-reload
uvicorn main:app --workers 4Production with 4 workers
fastapi dev main.pyNew CLI (FastAPI 0.111+)

Route decorators

Routes
Decorators
@app.get("/path")GET request
@app.post("/path", status_code=201)POST with custom status
@app.put("/path/{id}")PUT (full replace)
@app.patch("/path/{id}")PATCH (partial update)
@app.delete("/path/{id}", status_code=204)DELETE
@app.get("/", response_model=MySchema)Filter/validate response
@app.get("/", deprecated=True)Mark as deprecated in docs

Parameter types

Params
Where a value comes from
Path(..., gt=0, description="...")Path param with validation
Query(None, alias="page-num")Optional query with alias
Header(None)Read HTTP header
Cookie(None)Read cookie value
File(...) / UploadFileFile upload
Form(...)Form data

Comments

Sign in to leave a comment. Your name and photo come from Google; nothing else is shared.

Loading comments...