getRequest method
Make get request to api
Returns Map of the response. Throws an ApiException if the request is unsuccessful.
Implementation
Future<Map> getRequest(String path, {Map<String, dynamic>? params}) async {
// Convert param values to strings
Map<String, dynamic>? stringParams;
print("Constructing get request to $path");
if (params != null) {
// Parse param values
stringParams = Map.fromIterable(
params.keys,
key: (k) => k,
value: (k) => formatRequestParameter(params[k]),
);
}
final uri = getCausesApiPath(path, stringParams: stringParams);
print("Making request: ${uri.toString()}, headers: ${getRequestHeaders()}");
http.Response response = await client.get(
uri,
headers: getRequestHeaders(),
);
print("RESPONSE");
print(uri.toString());
print(response.body);
print(response.statusCode);
if (response.statusCode >= 400) {
throw getExceptionForResponse(response);
}
return await json.decode(response.body);
}