server.py 364 B

12345678910111213141516171819
  1. # Install dependencies: python3 -m pip install "uvicorn[standard]" fastapi
  2. # Run: uvicorn server:app --port 1234
  3. from fastapi import FastAPI
  4. from pydantic import BaseModel
  5. app = FastAPI()
  6. @app.get("/get")
  7. def hello():
  8. return "Hello World"
  9. class Item(BaseModel):
  10. field1: str
  11. field2: str
  12. @app.post("/post")
  13. def read_item(item: Item):
  14. return item