MCPcopy Create free account
hub / github.com/AstrBotDevs/AstrBot / json_response

Function json_response

astrbot/api/web.py:342–362  ·  view source on GitHub ↗

Build a JSON response for plugin Web API handlers. Args: data: JSON-serializable response body. status_code: HTTP status code. headers: Optional response headers. Returns: A Starlette/FastAPI JSON response.

(
    data: Any = None,
    *,
    status_code: int = 200,
    headers: dict[str, str] | None = None,
)

Source from the content-addressed store, hash-verified

340
341
342def json_response(
343 data: Any = None,
344 *,
345 status_code: int = 200,
346 headers: dict[str, str] | None = None,
347) -> JSONResponse:
348 """Build a JSON response for plugin Web API handlers.
349
350 Args:
351 data: JSON-serializable response body.
352 status_code: HTTP status code.
353 headers: Optional response headers.
354
355 Returns:
356 A Starlette/FastAPI JSON response.
357 """
358 return JSONResponse(
359 jsonable_encoder({} if data is None else data),
360 status_code=status_code,
361 headers=headers,
362 )
363
364
365def error_response(

Callers 3

error_responseFunction · 0.85

Calls

no outgoing calls

Tested by 2