| 1 | from fastapi import FastAPI |
| 2 | |
| 3 | app = FastAPI() |
| 4 | |
| 5 | @app.get("/") |
| 6 | def read_root(): |
| 7 | return {"Hello": "World"} |
| 8 | |
| 9 | @app.get("/landing") |
| 10 | def read_landing_page(): |
| 11 | return {"message": "Welcome to the landing page"} |
| 12 | |
| 13 | --- |
| 14 | |
| 15 | from fastapi import FastAPI, HTTPException |
| 16 | |
| 17 | # ... same ... |
| 18 | |
| 19 | @app.get("/landing") |
| 20 | def read_landing_page(): |
| 21 | raise HTTPException(status_code=404, detail="Page not found") |
| 22 | |
| 23 | --- |
| 24 | |
| 25 | - from fastapi import FastAPI |
| 26 | + from fastapi import FastAPI, HTTPException |
| 27 | |
| 28 | app = FastAPI() |
| 29 | |
| 30 | @app.get("/") |
| 31 | def read_root(): |
| 32 | return {"Hello": "World"} |
| 33 | |
| 34 | @app.get("/landing") |
| 35 | def read_landing_page(): |
| 36 | - return {"message": "Welcome to the landing page"} |
| 37 | + raise HTTPException(status_code=404, detail="Page not found") |