post<T> static method

Future<T> post<T>(
  1. String url,
  2. dynamic body, {
  3. dynamic mapper(
    1. Map<String, dynamic>
    )?,
})

Implementation

static Future<T> post<T>(String url, dynamic body,
    {Function(Map<String, dynamic>)? mapper}) async {
  try {
    final response = await _client.post(Uri.parse(apiUrl + url),
        headers: headers, body: body != null ? jsonEncode(body) : null);
    validateResponse(response);
    final jsonResponse = IApillonResponse.fromJson(jsonDecode(response.body));
    if (mapper != null) {
      return mapper(jsonResponse.data);
    }
    return jsonResponse.data;
  } on SocketException {
    throw ApillonNetworkError('No Internet connection');
  } on HttpException catch (e) {
    ApillonLogger.log(e.message, LogLevel.ERROR);
    throw ApillonRequestError(e.message);
  } on FormatException catch (e) {
    ApillonLogger.log(e.message, LogLevel.ERROR);
    throw ApillonRequestError(e.message);
  }
}