jsonParser static method

dynamic jsonParser(
  1. Req req,
  2. Res res,
  3. Function next
)

Implementation

static jsonParser(Req req, Res res, Function next) {
  if (req.headers.contentType?.mimeType == 'application/json' &&
      req.method != 'OPTIONS' &&
      req.method != 'GET') {
    String requestBody = "{}";
    var bytes =
        Uint8List.fromList(req.bodyStream.expand((chunk) => chunk).toList());
    requestBody = utf8.decode(bytes);
    req.body = jsonDecode(requestBody);
  }
  next();
}