-def format_response(request: Request, result: Any) -> Response:
- """ Render response into a string according to the formatter
- set in `parse_format()`.
- """
- fmt = request.state.format
- return Response(request.state.formatter.format(result, fmt),
- media_type=CONTENT_TYPE.get(fmt, 'application/json'))
+ def error(self, msg: str, status: int = 400) -> HTTPException:
+ return HTTPException(status, detail=msg,
+ headers={'content-type': self.content_type})
+
+
+ def create_response(self, status: int, output: str, num_results: int) -> Response:
+ self.request.state.num_results = num_results
+ return Response(output, status_code=status, media_type=self.content_type)
+
+
+ def config(self) -> Configuration:
+ return cast(Configuration, self.request.app.state.API.config)