Created
          May 14, 2021 01:14 
        
      - 
      
 - 
        
Save matutter/d8203cc8ded6975b14eb9225ecd6fd66 to your computer and use it in GitHub Desktop.  
    Very simple fast api example
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | """ | |
| 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