Plain is headed towards 1.0! Subscribe for development updates →

plain.api

 1from plain import http
 2
 3
 4class JsonResponseList(http.JsonResponse):
 5    openapi_description = "List of objects"
 6
 7    def __init__(self, data, *args, **kwargs):
 8        if not isinstance(data, list):
 9            raise TypeError("data must be a list")
10        kwargs["safe"] = False  # Allow a list to be dumped instead of a dict
11        super().__init__(data, *args, **kwargs)
12
13
14class JsonResponseCreated(http.JsonResponse):
15    status_code = 201
16    openapi_description = "Created"
17
18
19class JsonResponseBadRequest(http.JsonResponse):
20    status_code = 400
21    openapi_description = "Bad request"
22
23
24class HttpNoContentResponse(http.Response):
25    status_code = 204
26    openapi_description = "No content"
27
28
29class Response(http.Response):
30    openapi_description = "OK"
31
32
33class ResponseBadRequest(http.ResponseBadRequest):
34    openapi_description = "Bad request"
35
36
37class ResponseNotFound(http.ResponseNotFound):
38    openapi_description = "Not found"
39
40
41class JsonResponse(http.JsonResponse):
42    openapi_description = "OK"