ZCoreAPIRoute & Web Adapters
API reference for ZCoreAPIRoute, request body caching, and dynamic OpenAPI schema interceptors.
ZCoreAPIRoute extends FastAPI's standard APIRoute. It configures routes to use ZCoreJSONResponse, binds operational action contexts, and manages HTTP Vary caching headers for restricted fields.
Class Definition
from fastapi.routing import APIRoute
from zcore.web import ZCoreAPIRoute
class ZCoreAPIRoute(APIRoute):
def __init__(self, *args: Any, **kwargs: Any):
...Attributes
Prop
Type
Execution Flow & Lifecycle Interception
Route Execution Pipeline:
- Unified Response Class Swap: If
response_classis standardJSONResponse, it is swapped toZCoreJSONResponseto use the unified serialization pipeline (json_dumps). - Context Action Binding: Resolves the operational action (from
openapi_extra["action"]or falling back to HTTP method mapping) and binds it to context viactx.set("action", custom_action). - CDN Cache Protection (
VaryHeader): Ifctx.restricted_fieldsare active on a JSON response,ZCoreAPIRouteautomatically appendsVary: Authorization, Cookieto prevent intermediate proxies or CDN caches from serving masked responses to unrestricted users.
Helper Classes & Functions
ZCoreRequest
Custom HTTP Request subclass that caches the raw body byte stream to prevent multi-read stream lockups downstream:
from zcore.web import ZCoreRequest
class ZCoreRequest(Request):
async def body(self) -> bytes:
# Caches and returns evaluated request payload bytes
...ZCoreJSONResponse
Specialized JSONResponse subclass rendering payloads through ZCore's custom serialization pipeline (json_dumps), supporting ISO dates, Decimals, UUIDs, and Pydantic models:
from zcore.web import ZCoreJSONResponse
class ZCoreJSONResponse(JSONResponse):
def render(self, content: Any) -> bytes:
return json_dumps(content).encode("utf-8")Schema Discovery Helpers
These utility functions inspect FastAPI route signatures to locate the target Pydantic models:
find_input_schema(dependant: Any) -> type[BaseModel] | None: Analyzes route body parameters onPOST,PUT, andPATCHendpoints to resolve creation/update input models.find_output_schema(response_model: Any) -> type[BaseModel] | None: Recursively unpacks generic types (likeResponseWrapper[list[TaskResponse]]) onGETendpoints to extract the underlying response model.
BaseRouter
Comprehensive API reference for the BaseRouter class, RouteKey enumeration, lookup projections, schema introspection, custom route hooks, and endpoint overrides.
Zchema (Schema Projection)
API reference for the Zchema base class used for dynamic, role-based field pruning and context shielding.