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