-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
thr3a
committed
Dec 20, 2024
1 parent
d2046d2
commit d5f5280
Showing
8 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/.venv | ||
.env | ||
__pycache__ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"[python]": { | ||
"editor.defaultFormatter": "charliermarsh.ruff", | ||
"editor.formatOnSave": true | ||
} | ||
} |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from fastapi import FastAPI | ||
|
||
from .routers import items | ||
|
||
app = FastAPI() | ||
|
||
app.include_router(items.router) | ||
|
||
|
||
@app.get("/") | ||
async def root(): | ||
return {"message": "Hello Bigger Applications!"} |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from fastapi import APIRouter, HTTPException | ||
|
||
router = APIRouter( | ||
prefix="/items", | ||
tags=["items"], | ||
responses={404: {"description": "Not found"}}, | ||
) | ||
fake_items_db = {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}} | ||
|
||
|
||
@router.get("/") | ||
async def read_items(): | ||
return fake_items_db | ||
|
||
|
||
@router.get("/{item_id}") | ||
async def read_item(item_id: str): | ||
if item_id not in fake_items_db: | ||
raise HTTPException(status_code=404, detail="Item not found") | ||
return {"name": fake_items_db[item_id]["name"], "item_id": item_id} | ||
|
||
|
||
@router.put( | ||
"/{item_id}", | ||
tags=["custom"], | ||
responses={403: {"description": "Operation forbidden"}}, | ||
) | ||
async def update_item(item_id: str): | ||
if item_id != "plumbus": | ||
raise HTTPException( | ||
status_code=403, detail="You can only update the item: plumbus" | ||
) | ||
return {"item_id": item_id, "name": "The great Plumbus"} | ||
|
||
|
||
# from typing import Union | ||
|
||
# from fastapi import FastAPI | ||
|
||
# app = FastAPI() | ||
|
||
|
||
# @app.get("/") | ||
# def read_root(): | ||
# return {"Hello": "World"} | ||
|
||
|
||
# @app.get("/items/{item_id}") | ||
# def read_item(item_id: int, q: Union[str, None] = None): | ||
# return {"item_id": item_id, "q": q} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ readme = "README.md" | |
requires-python = ">=3.12" | ||
dependencies = [ | ||
"fastapi[standard]>=0.115.6", | ||
"ruff>=0.8.4", | ||
] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.