Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3 - showcases the usage of CVB in FastAPI #82

Merged
merged 15 commits into from
Mar 17, 2023
Merged

V3 - showcases the usage of CVB in FastAPI #82

merged 15 commits into from
Mar 17, 2023

Conversation

yezz123
Copy link
Owner

@yezz123 yezz123 commented Mar 14, 2023

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

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)

@yezz123 yezz123 added bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request Extra Large Large dependencies Pull requests that update a dependency file github_actions Pull requests that update GitHub Actions code python Pull requests that update Python code labels Mar 14, 2023
@yezz123 yezz123 self-assigned this Mar 14, 2023
@yezz123 yezz123 linked an issue Mar 14, 2023 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Mar 14, 2023

Codecov Report

Patch coverage: 92.12% and project coverage change: -5.98 ⚠️

Comparison is base (a2eb312) 98.19% compared to head (760f6af) 92.21%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #82      +/-   ##
==========================================
- Coverage   98.19%   92.21%   -5.98%     
==========================================
  Files           6       11       +5     
  Lines         166      257      +91     
==========================================
+ Hits          163      237      +74     
- Misses          3       20      +17     
Impacted Files Coverage Δ
fastapi_class/logger.py 0.00% <0.00%> (ø)
tests/test_views.py 79.66% <79.66%> (ø)
fastapi_class/exceptions.py 90.90% <90.90%> (ø)
tests/test_routers.py 94.87% <94.87%> (ø)
fastapi_class/views.py 97.14% <97.14%> (ø)
fastapi_class/routers.py 97.43% <97.43%> (ø)
fastapi_class/__init__.py 100.00% <100.00%> (ø)
fastapi_class/openapi.py 100.00% <100.00%> (ø)
tests/test_exceptions.py 100.00% <100.00%> (ø)
tests/test_openapi.py 100.00% <100.00%> (ø)
... and 1 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@yezz123 yezz123 merged commit cc82565 into main Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation enhancement New feature or request Extra Large github_actions Pull requests that update GitHub Actions code Large python Pull requests that update Python code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

showcases the usage of CVB in FastAPI
1 participant