Skip to content

Instantly share code, notes, and snippets.

@davila7
Created September 5, 2024 19:58
Show Gist options
  • Select an option

  • Save davila7/c2cd473c7eb628d2e46c5ad2501653db to your computer and use it in GitHub Desktop.

Select an option

Save davila7/c2cd473c7eb628d2e46c5ad2501653db to your computer and use it in GitHub Desktop.
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello1": "World"}
@app.get("/items/")
def read_items():
return [{"name": "Item Foo"}, {"name": "Item Bar"}]
@app.get("/items/{item_id}")
def read_item(item_id: int):
return {"item_id": item_id}
@app.post("/items/")
def create_item(name: str, price: float):
return {"name": name, "price": price}
@app.put("/items/{item_id}")
def update_item(item_id: int, name: str, price: float):
return {"item_id": item_id, "name": name, "price": price}
@app.delete("/items/{item_id}")
def delete_item(item_id: int):
return {"item_id": item_id}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment