MCPcopy
hub / github.com/sanic-org/sanic / json

Function json

sanic/response/convenience.py:36–64  ·  view source on GitHub ↗

Returns response object with body in json format. Args: body (Any): Response data to be serialized. status (int, optional): HTTP response code. Defaults to `200`. headers (Dict[str, str], optional): Custom HTTP headers. Defaults to `None`. content_type (str, opti

(
    body: Any,
    status: int = 200,
    headers: dict[str, str] | None = None,
    content_type: str = "application/json",
    dumps: Callable[..., AnyStr] | None = None,
    **kwargs: Any,
)

Source from the content-addressed store, hash-verified

34
35
36def json(
37 body: Any,
38 status: int = 200,
39 headers: dict[str, str] | None = None,
40 content_type: str = "application/json",
41 dumps: Callable[..., AnyStr] | None = None,
42 **kwargs: Any,
43) -> JSONResponse:
44 """Returns response object with body in json format.
45
46 Args:
47 body (Any): Response data to be serialized.
48 status (int, optional): HTTP response code. Defaults to `200`.
49 headers (Dict[str, str], optional): Custom HTTP headers. Defaults to `None`.
50 content_type (str, optional): The content type (string) of the response. Defaults to `"application/json"`.
51 dumps (Callable[..., AnyStr], optional): A custom json dumps function. Defaults to `None`.
52 **kwargs (Any): Remaining arguments that are passed to the json encoder.
53
54 Returns:
55 JSONResponse: A response object with body in json format.
56 """ # noqa: E501
57 return JSONResponse(
58 body,
59 status=status,
60 headers=headers,
61 content_type=content_type,
62 dumps=dumps,
63 **kwargs,
64 )
65
66
67def text(

Callers 15

_respondMethod · 0.90
handlerFunction · 0.90
sampleFunction · 0.90
putFunction · 0.90
deleteFunction · 0.90
handle_cancelFunction · 0.90
list_resources_handlerFunction · 0.90
get_resource_handerFunction · 0.90
default_routeFunction · 0.90
bp3_r1Function · 0.90
pre_groupFunction · 0.90
r1Function · 0.90

Calls 1

JSONResponseClass · 0.85

Tested by 15

handlerFunction · 0.72
sampleFunction · 0.72
putFunction · 0.72
deleteFunction · 0.72
handle_cancelFunction · 0.72
list_resources_handlerFunction · 0.72
get_resource_handerFunction · 0.72
default_routeFunction · 0.72
bp3_r1Function · 0.72
pre_groupFunction · 0.72
r1Function · 0.72
r2Function · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…