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

Demo

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.1.1.tar.gz (4.2 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.1.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for fastapi_exception_responses-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bafa0f84e5d882c06c6d6c5e8462a4695a45cb4acf5853c30b1039aa7a079789
MD5 0f9341f946d4cd516feb1e3241c229aa
BLAKE2b-256 12e3d9573d042ab6f6f2d9297f3beb30c607791f4d18c4e7e6ab9ed90ee9202e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_exception_responses-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f88b89c5caa2fdc519b03179cbdb1776e2bfafcdfd85a5a1f249d4554b2d7ce8
MD5 17dd4c577347a08bdeb68444a159932c
BLAKE2b-256 5cbac4fd6f2d45fd67bce2ed1a042b3042c68392a816d13c50151c714a2630e4

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