pre-commit-ci-lite[bot]
1 month ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
7 additions and
0 deletions
-
README.md
|
|
|
@ -187,6 +187,13 @@ app = FastAPI() |
|
|
|
async def read_root(): |
|
|
|
return {"Hello": "World"} |
|
|
|
|
|
|
|
#### Explanation |
|
|
|
|
|
|
|
- `@app.get("/")` defines an HTTP GET endpoint for the root URL (`/`) |
|
|
|
- When a client accesses this URL, the function `read_root()` is executed |
|
|
|
- The returned dictionary is automatically converted into a JSON response |
|
|
|
|
|
|
|
This shows how FastAPI maps routes directly to Python functions. |
|
|
|
|
|
|
|
@app.get("/items/{item_id}") |
|
|
|
async def read_item(item_id: int, q: str | None = None): |
|
|
|
|