Home / File/ tutorial002_py310.py — fastapi Source File

tutorial002_py310.py — fastapi Source File

Architecture documentation for tutorial002_py310.py, a python file in the fastapi codebase. 6 imports, 0 dependents.

File python FastAPI Responses 6 imports 1 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  32cf0138_5dda_0a0d_8b8e_bf7910851ce9["tutorial002_py310.py"]
  07d79a2e_d4e9_0bbb_be90_936274444c8c["collections.abc"]
  32cf0138_5dda_0a0d_8b8e_bf7910851ce9 --> 07d79a2e_d4e9_0bbb_be90_936274444c8c
  534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"]
  32cf0138_5dda_0a0d_8b8e_bf7910851ce9 --> 534f6e44_61b8_3c38_8b89_6934a6df9802
  01c652c5_d85c_f45e_848e_412c94ea4172["exceptions.py"]
  32cf0138_5dda_0a0d_8b8e_bf7910851ce9 --> 01c652c5_d85c_f45e_848e_412c94ea4172
  58bb043a_10d8_c308_5564_225558a63815["RequestValidationError"]
  32cf0138_5dda_0a0d_8b8e_bf7910851ce9 --> 58bb043a_10d8_c308_5564_225558a63815
  de395a51_26f8_3424_1af0_2f5bef39c893["routing.py"]
  32cf0138_5dda_0a0d_8b8e_bf7910851ce9 --> de395a51_26f8_3424_1af0_2f5bef39c893
  aa28685f_bb97_e988_ff40_3e5385960f32["APIRoute"]
  32cf0138_5dda_0a0d_8b8e_bf7910851ce9 --> aa28685f_bb97_e988_ff40_3e5385960f32
  style 32cf0138_5dda_0a0d_8b8e_bf7910851ce9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from collections.abc import Callable

from fastapi import Body, FastAPI, HTTPException, Request, Response
from fastapi.exceptions import RequestValidationError
from fastapi.routing import APIRoute


class ValidationErrorLoggingRoute(APIRoute):
    def get_route_handler(self) -> Callable:
        original_route_handler = super().get_route_handler()

        async def custom_route_handler(request: Request) -> Response:
            try:
                return await original_route_handler(request)
            except RequestValidationError as exc:
                body = await request.body()
                detail = {"errors": exc.errors(), "body": body.decode()}
                raise HTTPException(status_code=422, detail=detail)

        return custom_route_handler


app = FastAPI()
app.router.route_class = ValidationErrorLoggingRoute


@app.post("/")
async def sum_numbers(numbers: list[int] = Body()):
    return sum(numbers)

Domain

Subdomains

Functions

Frequently Asked Questions

What does tutorial002_py310.py do?
tutorial002_py310.py is a source file in the fastapi codebase, written in python. It belongs to the FastAPI domain, Responses subdomain.
What functions are defined in tutorial002_py310.py?
tutorial002_py310.py defines 1 function(s): sum_numbers.
What does tutorial002_py310.py depend on?
tutorial002_py310.py imports 6 module(s): APIRoute, RequestValidationError, __init__.py, collections.abc, exceptions.py, routing.py.
Where is tutorial002_py310.py in the architecture?
tutorial002_py310.py is located at docs_src/custom_request_and_route/tutorial002_py310.py (domain: FastAPI, subdomain: Responses, directory: docs_src/custom_request_and_route).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free