Skip to main content

🪄 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          ", user.list_)
route("GET     /api/users/{user_id}", user.get)
route("POST    /api/users          ", user.create)
route("PATCH   /api/users/{user_id}", user.update)
route("DELETE  /api/users/{user_id}", user.delete_)

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)


# 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

fastapi_magic_router-0.2.0.tar.gz (4.6 kB view hashes)

Uploaded Source

Built Distribution

fastapi_magic_router-0.2.0-py3-none-any.whl (4.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page