postJson method

Future<Response> postJson(
  1. String path,
  2. Map<String, dynamic> body, {
  3. String? contentType,
  4. Map<String, String>? headers,
})

Implementation

Future<Response> postJson(String path, Map<String, dynamic> body, {String? contentType, Map<String, String>? headers}) async {
  if (path.startsWith("/")) {
    path = path.substring(1);
  }
  final url = baseUrl.resolve(path);
  final bodyText = jsonEncode(body);
  return httpClient.post(url,
      headers: getHeaders({"content-type": contentType ?? "application/json", if (headers != null) ...headers}), body: bodyText);
}