Example
fastapi_cls demo
-
Create a file
view.pywith:from pydantic import BaseModel from fastapi import Depends class User(BaseModel): username: str email: Optional[str] = None full_name: Optional[str] = None disabled: Optional[bool] = None async def get_user(): return User(username="john") class ItemView: user: User = Depends(get_user) def get(self) -> User: return self.user def post(self) -> str: self.user.username = 'change name' return "ok"
-
Create a file
route.pywith:from fastapi_cls import ClassRouter router = ClassRouter() router.add_resource("/item",ItemView,methods=["GET","POST"])
Or, if you want to define your owner method reflect to http method. you can do like this.
from fastapi_cls import ClassRouter router = ClassRouter() router.add_method_route("/item",ItemView,ItemView.get, methods=["GET"]) router.add_method_route("/item",ItemView,ItemView.post, methods=["POST"])
Its equivalent to
-
fastapi
from fastapi import ApiRouter, Depends class User(BaseModel): username: str email: Optional[str] = None full_name: Optional[str] = None disabled: Optional[bool] = None async def get_user(): return User(username="john") router = ApiRouter() @router.get('/item') def get(user: User = Depends(get_user)) -> User: return user @router.post('/item') def post(user: User = Depends(get_user)) -> str: user.username = 'change name' return "ok"
In this case. The
ItemViewmethodsgetandpostwill bind on router as a function.
Metadata
Release files for fastapi-cls 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastapi_cls-0.1.3.tar.gz | 4.6 kB | Without provenance | Details for fastapi_cls-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_cls-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for fastapi_cls-0.1.3-py3-none-any.whl |
Total release size: 10.2 kB
Release files / fastapi_cls-0.1.3.tar.gz
| Download URL | fastapi_cls-0.1.3.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
31fc62761f304115a8b5226c87456f273798f7b2f3bba461b0e05fa6012f0877
|
|
BLAKE2b-256 checksum How to use checksums |
22c85d462bf831b2fbb1f1a51a919cd28662663c5b04756dc14c546898c22289
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.0 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.7
|
Release files / fastapi_cls-0.1.3-py3-none-any.whl
| Download URL | fastapi_cls-0.1.3-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
063285720660b037dcb3016d54cdd1e0eb0b2a9969904b15cd7c2b2af45d62d6
|
|
BLAKE2b-256 checksum How to use checksums |
a72c214e72536af7af8aea92f0c2924eb1dca1dc860d689a48472486aeeae200
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.0 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.7
|
Security for fastapi-cls 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.