No project description provided
Project description
fastapi_kit
认证
from fastapi import FastAPI
from fastapi_kit.auth import register_auth
app = FastAPI(...)
register_auth(app)
完成以上操作,即可在request
中拿到user
异常
内置异常:
ExistException
对于已经存在的异常NoPermissionException
对于无权限操作的异常NotFoundException
对于不存在的异常OverLimitException
对于超出限制的异常
对于自定义的业务报错,可以继承CustomException
直接在业务处抛错。
注意:自定义异常类,需要使用app.add_exception_handler
来注册。
from fastapi_kit.exception import error_exception_handler
app.add_exception_handler(自定义异常类, error_exception_handler)
权限
直接在路由定义处设置权限
from fastapi import APIRouter, Request
from fastapi_kit.permission import permission
router = APIRouter()
@router.post('/subscribe')
@permission('bidding_subscribe_create')
async def subscribe(request: Request):
""" 创建用户订阅器 """
通用schema返回
对于正常的数据返回,使用RestfulResponse
对于具有翻页的数据返回,使用RestfulPageResponse
RestfulResponse
from fastapi_kit.schema import RestfulResponse
@router.post('/subscribe', response_model=RestfulResponse[对象的schema])
async def subscribe(request):
""" 创建用户订阅器 """
return dict(data=对象)
RestfulPageResponse
(常用于列表)
from fastapi_kit.schema import RestfulPageResponse
@router.get('/subscribe', response_model=RestfulPageResponse[List[对象的schema]])
async def subscribe(request):
""" 获取用户订阅器 """
return RestfulPageResponse(data=对象)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fastapi_kit-0.1.2.tar.gz
(3.7 kB
view details)
Built Distribution
File details
Details for the file fastapi_kit-0.1.2.tar.gz
.
File metadata
- Download URL: fastapi_kit-0.1.2.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.4 Darwin/22.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32ffc5a20a006e4e1fbf3cd1d12b0f48ad1eea144690ccb9c6e1f2076facdd9b |
|
MD5 | 5456c499bd6b010ddef4ebe1af019eac |
|
BLAKE2b-256 | 830485929a979eabfe1626922d8f80600eb82e240877a2e66863f1c2180be00e |
File details
Details for the file fastapi_kit-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: fastapi_kit-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.4 Darwin/22.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19b5cb854fab67ae595597f5619d58cfb5277e776f1bc33b68a4dc6cb663157b |
|
MD5 | e60352a4416ec1a5afafda724ddb36af |
|
BLAKE2b-256 | 8e16f797507583cc1d028e59baf51c72ba754532628daa4908edb96975caa522 |