Skip to content

Releases: yezz123/fastapi-class

3.6.0

20 Apr 16:47
c7a8be0
Compare
Choose a tag to compare

Fixes

  • 🐛 Fix issue with @endpoint decorator & Setup uv by @yezz123 in #182

Dependencies

3.5.0

07 Feb 22:00
34efdde
Compare
Choose a tag to compare

What's Changed

Fixes 🐛

  • ♻️ Refactor CI workflow for linting and testing by @yezz123 in #162
  • ♻️ Update ruff to v0.2.0 & fix type hints by @yezz123 in #163

Dependencies ⬆️

Full Changelog: 3.4.0...3.5.0

3.4.0

13 Dec 21:32
b8d2be6
Compare
Choose a tag to compare

What's Changed

Fixes 🐛

Dependencies 📦

New Contributors

Full Changelog: 3.3.0...3.4.0

3.3.0

24 Apr 01:35
b93c8dc
Compare
Choose a tag to compare

What's Changed

  • Supporting python 3.8 & 3.9

New Contributors

Full Changelog: 3.2.0...3.3.0

3.2.0

22 Apr 21:23
1947b22
Compare
Choose a tag to compare

What's Changed

  • Feat: Customise status code & Enhance exceptions by @yezz123 in #100

Dependencies 🔨

Full Changelog: 3.1.0...3.2.0

3.1.0

25 Mar 11:48
8e3ed62
Compare
Choose a tag to compare

⚠️ Drop Support of Python 3.8 | 3.9 & New Break Changes

As you create more complex FastAPI applications, you may find yourself frequently repeating the same dependencies in multiple related endpoints.

We Introduce this new version showcases the usage of CVB in FastAPI by @yezz123 in #82

A common question people have as they become more comfortable with FastAPI is how they can reduce the number of times they have to copy/paste the same dependency into related routes.

fastapi_class provides a class-based view decorator @View to help reduce the amount of boilerplate necessary when developing related routes.

Highly inspired by Fastapi-utils, Thanks to @dmontagu for the great work.

  • Example:
from fastapi import FastAPI, APIRouter, Query
from pydantic import BaseModel
from fastapi_class import View

app = FastAPI()
router = APIRouter()

class ItemModel(BaseModel):
    id: int
    name: str
    description: str = None

@View(router)
class ItemView:
    def post(self, item: ItemModel):
        return item

    def get(self, item_id: int = Query(..., gt=0)):
        return {"item_id": item_id}

app.include_router(router)

Response model 📦

Exception in list need to be either function that return fastapi.HTTPException itself. In case of a function it is required to have all of it's arguments to be optional.

from fastapi import FastAPI, APIRouter, HTTPException, status
from fastapi.responses import PlainTextResponse
from pydantic import BaseModel

from fastapi_class import View

app = FastAPI()
router = APIRouter()

NOT_AUTHORIZED = HTTPException(401, "Not authorized.")
NOT_ALLOWED = HTTPException(405, "Method not allowed.")
NOT_FOUND  = lambda item_id="item_id": HTTPException(404, f"Item with {item_id} not found.")

class ItemResponse(BaseModel):
    field: str | None = None

@view(router)
class MyView:
    exceptions = {
        "__all__": [NOT_AUTHORIZED],
        "put": [NOT_ALLOWED, NOT_FOUND]
    }

    RESPONSE_MODEL = {
        "put": ItemResponse
    }

    RESPONSE_CLASS = {
        "delete": PlainTextResponse
    }

    def get(self):
        ...
    def put(self):
        ...
    def delete(self):
        ...

app.include_router(router)

Customized Endpoints

from fastapi import FastAPI, APIRouter, HTTPException
from fastapi.responses import PlainTextResponse
from pydantic import BaseModel

from fastapi_class import View, endpoint

app = FastAPI()
router = APIRouter()

NOT_AUTHORIZED = HTTPException(401, "Not authorized.")
NOT_ALLOWED = HTTPException(405, "Method not allowed.")
NOT_FOUND  = lambda item_id="item_id": HTTPException(404, f"Item with {item_id} not found.")
EXCEPTION = HTTPException(400, "Example.")

class UserResponse(BaseModel):
    field: str | None = None

@View(router)
class MyView:
    exceptions = {
        "__all__": [NOT_AUTHORIZED],
        "put": [NOT_ALLOWED, NOT_FOUND],
        "edit": [EXCEPTION]
    }

    RESPONSE_MODEL = {
        "put": UserResponse,
        "edit": UserResponse
    }

    RESPONSE_CLASS = {
        "delete": PlainTextResponse
    }

    def get(self):
        ...
    def put(self):
        ...
    def delete(self):
        ...
    @endpoint(("PUT",), path="edit")
    def edit(self):
        ...

Dependencies 🔨

Full Changelog: 2.0.0...3.1.0

🔖 2.0.0

08 Jan 14:41
85947c4
Compare
Choose a tag to compare

What's Changed

New Contributors

  • @lgtm-com made their first contribution in #56

Full Changelog: 1.1.2...2.0.0

1.1.2

30 Nov 15:44
f05440f
Compare
Choose a tag to compare

What's Changed

Full Changelog: 1.1.1...1.1.2

Build Documentation & Switch to Python 3.10 ✨

17 Oct 02:49
9333bad
Compare
Choose a tag to compare

What's Changed

Pull Requests

Full Changelog: 1.1.0...1.1.1

Add More Classifiers & Fix Typo ✨

10 Oct 00:51
fb59eba
Compare
Choose a tag to compare

What's Changed

  • Add More Classifiers & Fix Typo ✨ by @yezz123 in #3

Full Changelog: 1.0.0...1.1.0