🪄 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
File details
Details for the file fastapi_magic_router-0.1.0.tar.gz
.
File metadata
- Download URL: fastapi_magic_router-0.1.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b72d4cfdc35e9f28a4edc1b51d07fee248f0916422105f5b29555aec997a6ce |
|
MD5 | 010e88b09063e7c95e2b4150da4c15ad |
|
BLAKE2b-256 | 04843ad304fac48d75d7bcc3f8efe8f7217e7545a900ebfec9ab25d5094eff2b |
File details
Details for the file fastapi_magic_router-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: fastapi_magic_router-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60e57c5c60502611f86db7e732e6dc5a8c34f41349e5a6bbdd9a1189ff5b5457 |
|
MD5 | 02ec60d95f215f88b2dbd6edc9e89d24 |
|
BLAKE2b-256 | 0c25a259bf73cbd8c8b50e3ce7eb6dcc59f68229869dc16cc008d05ec6b3ed89 |