postAndGetList<T> function

Future<ApiResponse<List<T>>> postAndGetList<T>({
  1. required String url,
  2. required Map<String, dynamic> body,
  3. required FromJson<T> fromJson,
  4. GetHeaders? headers,
  5. Duration? timeout,
})

Make a POST request sending a json object, with an optional json list response

Implementation

Future<ApiResponse<List<T>>> postAndGetList<T>({
  required String url,
  required Map<String, dynamic> body,
  required FromJson<T> fromJson,
  GetHeaders? headers,
  Duration? timeout,
}) async {
  try {
    var _headers = headers != null ? await headers() : _defaultHeaders;
    var requestFuture =
        _client.post(Uri.parse(url), headers: _headers, body: jsonEncode(body));
    var response = await _makeRequest(requestFuture, timeout);
    return _handleListResult('POST', url, response, fromJson);
  } on Exception catch (e, stack) {
    _onException('POST', url, -1, e, stack);
    return ApiResponse(-1, error: e.toString());
  }
}