Home / Function/ serialize_response() — fastapi Function Reference

serialize_response() — fastapi Function Reference

Architecture documentation for the serialize_response() function in routing.py from the fastapi codebase.

Function python FastAPI Routing calls 1 called by 1

Entity Profile

Dependency Diagram

graph TD
  ef417485_6bd2_0f62_cc05_f62f181d92fc["serialize_response()"]
  de395a51_26f8_3424_1af0_2f5bef39c893["routing.py"]
  ef417485_6bd2_0f62_cc05_f62f181d92fc -->|defined in| de395a51_26f8_3424_1af0_2f5bef39c893
  ad8d62d9_53da_514b_c06f_53293eb1e5ae["get_request_handler()"]
  ad8d62d9_53da_514b_c06f_53293eb1e5ae -->|calls| ef417485_6bd2_0f62_cc05_f62f181d92fc
  1ac1bc37_1a47_e7e2_9156_ab0473094700["jsonable_encoder()"]
  ef417485_6bd2_0f62_cc05_f62f181d92fc -->|calls| 1ac1bc37_1a47_e7e2_9156_ab0473094700
  style ef417485_6bd2_0f62_cc05_f62f181d92fc fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

fastapi/routing.py lines 264–303

async def serialize_response(
    *,
    field: Optional[ModelField] = None,
    response_content: Any,
    include: Optional[IncEx] = None,
    exclude: Optional[IncEx] = None,
    by_alias: bool = True,
    exclude_unset: bool = False,
    exclude_defaults: bool = False,
    exclude_none: bool = False,
    is_coroutine: bool = True,
    endpoint_ctx: Optional[EndpointContext] = None,
) -> Any:
    if field:
        if is_coroutine:
            value, errors = field.validate(response_content, {}, loc=("response",))
        else:
            value, errors = await run_in_threadpool(
                field.validate, response_content, {}, loc=("response",)
            )
        if errors:
            ctx = endpoint_ctx or EndpointContext()
            raise ResponseValidationError(
                errors=errors,
                body=response_content,
                endpoint_ctx=ctx,
            )

        return field.serialize(
            value,
            include=include,
            exclude=exclude,
            by_alias=by_alias,
            exclude_unset=exclude_unset,
            exclude_defaults=exclude_defaults,
            exclude_none=exclude_none,
        )

    else:
        return jsonable_encoder(response_content)

Domain

Subdomains

Defined In

Frequently Asked Questions

What does serialize_response() do?
serialize_response() is a function in the fastapi codebase, defined in fastapi/routing.py.
Where is serialize_response() defined?
serialize_response() is defined in fastapi/routing.py at line 264.
What does serialize_response() call?
serialize_response() calls 1 function(s): jsonable_encoder.
What calls serialize_response()?
serialize_response() is called by 1 function(s): get_request_handler.

Analyze Your Own Codebase

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

Try Supermodel Free