from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class People(BaseModel):
name: str
age: int
address: str = None
@app.post('/insert')
def insert(people: People):
age_after_10_years = people.age + 10
msg = f'Name: {people.name},age after ten years:{age_after_10_years}'
return {'success': True, 'msg': msg}
@app.get('/')
def index():
return {'message': 'Hi, this is your FastApi service!'}
run command: uvicorn main:app --reload, then you can access docs
http://127.0.0.1:8000/docs, you can test POST/GET as below or test it with Postman.