pythonasyncioapiasyncfastapiframeworkjsonjson-schemaopenapiopenapi3pydanticpython-typespython3redocreststarletteswaggerswagger-uiuvicornweb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
495 B
19 lines
495 B
from fastapi import FastAPI, Form, Depends
|
|
from pydantic import BaseModel
|
|
from fastapi.responses import JSONResponse
|
|
|
|
app = FastAPI()
|
|
|
|
class User(BaseModel):
|
|
name: str
|
|
age: int
|
|
|
|
def get_user(
|
|
name: str = Form(..., description="The user's name"),
|
|
age: int = Form(..., description="The user's age")
|
|
) -> User:
|
|
return User(name=name, age=age)
|
|
|
|
@app.post("/submit")
|
|
def submit(user: User = Depends(get_user)):
|
|
return JSONResponse(content={"name": user.name, "age": user.age})
|