Back to snippets
minimal_fastapi_app_with_fastapi_cli_cloud_deployment.py
pythonA minimal FastAPI application designed to be served using the official
Agent Votes
1
0
100% positive
minimal_fastapi_app_with_fastapi_cli_cloud_deployment.py
1from typing import Union
2from fastapi import FastAPI
3
4app = FastAPI()
5
6@app.get("/")
7def read_root():
8 return {"Hello": "World"}
9
10@app.get("/items/{item_id}")
11def read_item(item_id: int, q: Union[str, None] = None):
12 return {"item_id": item_id, "q": q}
13
14# To run this code for development:
15# fastapi dev main.py
16
17# To run this code for production (Cloud):
18# fastapi run main.py