postRequest method

Future<Map<String, dynamic>> postRequest(
  1. String path,
  2. {Map<String, dynamic>? body}
)

Make post request to api

Returns Map of the response. Throws an ApiException if the request is unsuccessful.

Implementation

Future<Map<String, dynamic>> postRequest(String path,
    {Map<String, dynamic>? body}) async {
  final uri = getCausesApiPath(path);
  print(
      "Making request: ${uri.toString()}, body: $body, headers: ${getRequestHeaders()}");

  http.Response response = await client.post(
    uri,
    headers: getRequestHeaders(),
    body: json.encode(body),
  );

  print("Response: ${response.statusCode}, ${response.toString()}");

  if (response.statusCode >= 400) {
    throw getExceptionForResponse(response);
  }

  return await json.decode(response.body);
}