Skip to content

Commit

Permalink
Added CRUDL routes
Browse files Browse the repository at this point in the history
  • Loading branch information
seekayel committed Aug 11, 2023
1 parent e2c4ca3 commit ba82473
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 28,20 @@ Run: `bin/start`
- runs a `uvicorn` server


## Try the server

Schema docs: [http://localhost:8181/docs](http://localhost:8181/docs)

Get an item:
`curl -i -XGET http://localhost:8181/item/1`

List items:
`curl -i -XGET http://localhost:8181/items/`

Post an item:
`curl -i -XPOST http://localhost:8181/items/ --data '{"item_id":1,"name":"Bob"}' -H 'content-type: application/json'`


## Questions / Help

Join us on Discord: [https://discord.cyclic.sh](https://discord.cyclic.sh)
Expand Down
27 changes: 27 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,11 1,38 @@
from fastapi import FastAPI
from fastapi.responses import FileResponse

from pydantic import BaseModel

from typing import Optional

app = FastAPI()


class Item(BaseModel):
item_id: int
name: Optional[str] = None


@app.get("/")
async def root():
return {"message": "Hello World"}


@app.get('/favicon.ico', include_in_schema=False)
async def favicon():
return FileResponse('favicon.ico')


@app.get("/item/{item_id}")
async def read_item(item_id: int):
return {"item_id": item_id}


@app.get("/items/")
async def list_items():
return [{"item_id": 1, "name": "Foo"}, {"item_id": 2, "name": "Bar"}]


@app.post("/items/")
async def create_item(item: Item):
return item
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 20,7 @@ python-multipart==0.0.6
PyYAML==6.0
sniffio==1.3.0
starlette==0.27.0
typing==3.7.4.3
typing_extensions==4.6.3
ujson==5.7.0
uvicorn==0.22.0
Expand Down

0 comments on commit ba82473

Please sign in to comment.