Skip to main content

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.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_exception_responses-0.2.2.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_exception_responses-0.2.2-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_exception_responses-0.2.2.tar.gz.

File metadata

File hashes

Hashes for fastapi_exception_responses-0.2.2.tar.gz
Algorithm Hash digest
SHA256 a32f9cd70990f19af72a74bbb6c406728e756f97daf338eecd3768774a09ef16
MD5 0294a1cae5c46c6fa56d384c4b40c88a
BLAKE2b-256 0c635c3c2ceff54c63ddfc3d89cd7e0a677a2e7db0373cc13848bb1052d06e9a

See more details on using hashes here.

File details

Details for the file fastapi_exception_responses-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_exception_responses-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9a986456d22c205f962fa409f52d8e43c443858e5c2d3bedb1d3e1f65a33983b
MD5 f2d19a19f12064037eb35d1a87e47120
BLAKE2b-256 ada27828f12260669c3ba4930e77377be27aa662fded99625350be84498ee4de

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page