fastapi-master/docs_src/response_model/tutorial002.py

20 lines
350 B
Python
Raw Normal View History

2024-08-24 12:41:47 +08:00
from typing import Union
from fastapi import FastAPI
from pydantic import BaseModel, EmailStr
app = FastAPI()
class UserIn(BaseModel):
username: str
password: str
email: EmailStr
full_name: Union[str, None] = None
# Don't do this in production!
@app.post("/user/")
async def create_user(user: UserIn) -> UserIn:
return user