Source code for aiida_restapi.jsonapi.responses

"""JSON:API responses module."""

from __future__ import annotations

from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse

from .models.base import JsonApiBaseDocument


[docs] class JsonApiResponse(JSONResponse): """Custom JSONResponse for JSON:API media type.""" media_type = 'application/vnd.api+json'
[docs] def render(self, content: JsonApiBaseDocument) -> bytes: content = jsonable_encoder(content, exclude_none=True) return super().render(content)