跳转到主要内容

🪄 具有魔法力量的FastAPI路由器 ✨

项目描述

🪄 FastAPI Magic Router ✨

您是否在寻找一种魔法般的方式来定义FastAPI路由?

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_)

来吧,我将满足您的愿望!

默认路由器与魔法路由器

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)

# --------------------------------------------------------------------------------------

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分发

fastapi_magic_router-0.2.0.tar.gz (4.6 kB 查看哈希值)

上传时间:

构建分发

fastapi_magic_router-0.2.0-py3-none-any.whl (4.4 kB 查看哈希)

上传时间: Python 3