ZCore LogoZCore
Api reference

ResponseWrapper

API reference for the generic JSON API response envelope and serialization container.

ResponseWrapper is a standardized generic Pydantic model that enforces a consistent payload structure for all application endpoints. It inherits from Zchema, meaning the encapsulated data payload participates natively in dynamic, role-based field pruning.

Class Definition

from typing import Generic, TypeVar, Optional, Any
from zcore import Zchema, ResponseWrapper

T = TypeVar("T")

class ResponseWrapper(Zchema, Generic[T]):
    success: bool = True
    message: str = "Success"
    data: Optional[T] = None
    meta: Optional[dict[str, Any]] = None

Attributes

Prop

Type


Class Methods

success_response

Convenience factory method constructing a successful ResponseWrapper container:

@classmethod
def success_response(
    cls, 
    data: T, 
    message: str = "Success", 
    meta: Optional[dict[str, Any]] = None
) -> ResponseWrapper[T]: ...

Prop

Type


Usage Example

from fastapi import APIRouter
from zcore import ResponseWrapper

router = APIRouter()

@router.get("/metrics")
async def get_metrics():
    stats = {"cpu_usage": 12.5, "uptime": 3600}
    return ResponseWrapper.success_response(
        data=stats, 
        message="Metrics resolved successfully"
    )

Automatic Router Integration: When using BaseRouter, you do not need to wrap return values manually. The router automatically encloses service outputs inside ResponseWrapper and populates pagination cursor metadata directly into meta.

On this page