← Back to Tutorials

35. Quick Guide

TaskCommand / Code
Installpip install fastapi uvicorn
Run dev serveruvicorn main:app --reload
Run productiongunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker
Create appapp = FastAPI()
GET endpoint@app.get("/path")
POST endpoint@app.post("/path")
Path paramdef func(item_id: int)
Query paramdef func(q: str = None)
Request bodydef func(item: Item)
Form datadef func(name: str = Form(...))
File uploaddef func(file: UploadFile = File(...))
Dependencydef func(db: Session = Depends(get_db))
Response model@app.get("/path", response_model=ItemOut)
Status code@app.post("/path", status_code=201)
Docs URL/docs (Swagger), /redoc (ReDoc)
Mount staticapp.mount("/static", StaticFiles(...))
CORSapp.add_middleware(CORSMiddleware, ...)
✏️ Exercise: Use this quick guide as a cheatsheet for your next FastAPI project. Try building a complete API without looking at the full chapters.