post static method

Future post(
  1. String path, {
  2. Object? payload = const {},
  3. Map<String, dynamic>? qparams,
  4. Uri? useUri,
  5. String? serviceID,
})

Implementation

static Future post(
  String path, {
  Object? payload = const {},
  Map<String, dynamic>? qparams,
  Uri? useUri,
  String? serviceID,
}) async {
  var client = http.Client();
  try {
    final response = await client.post(
      useUri ?? uri(path, queryparams: qparams, serviceID: serviceID),
      body: jsonEncode(payload),
      headers: _myHeaders(),
    );
    final decoded = json.decode(response.body);
    if ((response.statusCode / 100).truncate() != 2) {
      throw ApiErrorResponse(decoded["message"]);
    }
    return decoded["data"];
  } catch (e) {
    if (e is SocketException) throw ConnectionRefuted(err: e.message);
    if (e is HttpException) throw ApiErrorResponse("Couldn't find the post 😱");
    if (e is FormatException) throw RespuestaInvalida();
    rethrow;
  } finally {
    client.close();
  }
}