fastapi-responses generates HTTPExceptions and OpenAPI description for status codes
Project description
fastapi-responses
FastAPI Responses generates documentation for OpenAPI and Endpoints starlette
HTTPExceptions based on class attributes
defined as tuples of status code and detail
Usage
Configuration
from fastapi import APIRouter
()
from fastapi_exception_responses import Responses
router = APIRouter()
class DemoResponses(Responses):
NOT_VALID_EMAIL = 422, "Provided email is not valid."
NOT_VALID_USERNAME = 422, "Provided username is already in use."
WRONG_CREDENTIAL = 401, "Invalid username or password."
@router.get("/", responses=DemoResponses.get_responses())
async def get_demo():
if condition_one:
raise DemoResponses.NOT_VALID_USERNAME
elif condition_two:
raise DemoResponses.NOT_VALID_EMAIL
else:
raise DemoResponses.WRONG_CREDENTIAL
Result
https://github.com/max31ru12/fastapi-responses/blob/main/img.png
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_exception_responses-0.2.1.tar.gz.
File metadata
- Download URL: fastapi_exception_responses-0.2.1.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.11.9 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57b323cf0f33e08fd86edaaaa2ca145360d5deeee3b4325319f19ba50ae20e21
|
|
| MD5 |
40d778c29a2980aa6ecd830d122cc50e
|
|
| BLAKE2b-256 |
2d64cc3c5e83671f63d2e944b7b8b72940cace814ac00a3240b01179c6d30a84
|
File details
Details for the file fastapi_exception_responses-0.2.1-py3-none-any.whl.
File metadata
- Download URL: fastapi_exception_responses-0.2.1-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.11.9 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4940505941a09431d1a9cd126dfcac52907a08794dec2372348dcfc8510bfd95
|
|
| MD5 |
199e01186b7efdfdedb1a90c9551060a
|
|
| BLAKE2b-256 |
445c970c04c42427c31bf38fab88bb3a6c322539c8d1cf9f625096521bccdda2
|