Skip to content

Latest commit

 

History

History
46 lines (34 loc) · 1.74 KB

README.md

File metadata and controls

46 lines (34 loc) · 1.74 KB

logo

Downloads Downloads codecov Hits-of-Code Tests Python versions PyPI version Checked with mypy Ruff

A bit of dummy patching for FastAPI, class-based handlers. So far without self support.

Install it:

$ pip install cbfa

And use:

from typing import Optional
from fastapi import FastAPI
from pydantic import BaseModel
from cbfa import ClassBased


app = FastAPI()
wrapper = ClassBased(app)

class Item(BaseModel):
    name: str
    price: float
    is_offer: Optional[bool] = None

@wrapper('/item')
class Item:
    def get(item_id: int, q: Optional[str] = None):
        return {"item_id": item_id, "q": q}

    def post(item_id: int, item: Item):
        return {"item_name": item.name, "item_id": item_id}