🪄 FastAPI router with magical powers ✨
Project description
🪄 FastAPI Magic Router ✨
Have you come here seeking a magical way to define FastAPI routes?
app = FastAPI()
route = magic_router(app)
route("GET /api/users ", list_users)
route("GET /api/users/{user_id}", get_user)
route("POST /api/users ", create_user)
route("PATCH /api/users/{user_id}", update_user)
route("DELETE /api/users/{user_id}", delete_user)
Come, I shall grant you your wish!
Default Router vs Magic Router
from fastapi import FastAPI
from pydantic import BaseModel
from magic_router import magic_router, magic
class Response(BaseModel):
path: str
# Default Router -----------------------------------------------------------------------
app = FastAPI()
not_so_magical_path = "/api/not-so-magical"
async def not_so_magical_endpoint():
return Response(path=not_so_magical_path)
app.get(
not_so_magical_path,
response_model=Response,
tags=["main"],
operation_id="not_so_magical_endpoint",
name="not_so_magical_endpoint",
)(not_so_magical_endpoint)
# Magic Router -------------------------------------------------------------------------
route = magic_router(app)
async def magical_endpoint() -> Response:
return Response(path=magic(magical_endpoint).path)
route("GET /api/magical", magical_endpoint)
# --------------------------------------------------------------------------------------
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for fastapi_magic_router-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d6931be4443a21d9bca0d5de517269efad25beb42f47d213fc64598f38ac973 |
|
MD5 | 897375d22411620cb59912a5003eb52f |
|
BLAKE2b-256 | 7e22f5272b57a3848b3100adc98312d85ad5f4f384776f71e9d9a8833df6b256 |
Close
Hashes for fastapi_magic_router-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b34c45a3b3c02a437ee3ae62af293f24be5bbc2e91e6563e88e7b3c7a535dd32 |
|
MD5 | 5605d52cebf6d89ab77343e652028097 |
|
BLAKE2b-256 | d9404f595d8cfefc6c82e79e92056c0ffcfc50d9a6d1ec8115434864fca51a86 |