HttpPayload.json constructor

HttpPayload.json(
  1. Object? body, {
  2. Encoding encoding = utf8,
  3. String? contentType,
})

Encodes body as a JSON string and sets Content-Type to 'application/json'.

Implementation

HttpPayload.json(
  Object? body, {
  Encoding encoding = utf8,
  String? contentType,
})  : contentType =
          contentType ?? 'application/json; charset=${encoding.name}',
      super(
        LazyStream(
          () => Stream.value(encoding.encode(json.encode(body))),
        ),
      );