Skip to content

Instantly share code, notes, and snippets.

@matutter
Created May 14, 2021 01:14
Show Gist options
  • Save matutter/d8203cc8ded6975b14eb9225ecd6fd66 to your computer and use it in GitHub Desktop.
Save matutter/d8203cc8ded6975b14eb9225ecd6fd66 to your computer and use it in GitHub Desktop.
Very simple fast api example
"""
curl -d '{"data":"abc123"}' -H "Content-Type: application/json" -X POST http://localhost:8000/thing/data
"""
from fastapi import FastAPI
from pydantic import BaseModel
from starlette.requests import Request
app = FastAPI()
class ResponseModel(BaseModel):
data: str
status_code: int
class DataModel(BaseModel):
data: str
@app.post('/thing/data', response_model=ResponseModel)
async def add_data(request: Request, data: DataModel):
return ResponseModel(data=data.data, status_code=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment