FastAPI
Hello World fastAPIโ
- Create file
main.py
main.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
- Run:
uvicorn main:app - Open in browser:
http://127.0.0.1:8000 - View docs:
http://127.0.0.1:8000/docsorhttp://127.0.0.1:8000/redoc
Requestโ
- request body exampleโ๏ธ
- Import Pydantic's Base Model:
from pydantic import BaseModel. - Create data model.
- Declare it as parameter, with type as the data model created.
- Test in docs.
- Import Pydantic's Base Model: