json method

Future<HttpResponse> json([
  1. dynamic data
])

Sends JSON response with security headers.

Implementation

Future<HttpResponse> json([dynamic data]) async {
  response.headers.contentType = ContentType.json;
  _defaultHeaders.forEach((key, value) {
    response.headers.set(key, value);
  });

  return response
    ..statusCode = HttpStatus.ok
    ..write(jsonEncode(data))
    ..close();
}