post method

  1. @override
Future<Map<String, dynamic>> post(
  1. String api,
  2. Map<String, dynamic>? headers,
  3. Map<String, dynamic> body
)
override

Implementation

@override
Future<Map<String, dynamic>> post(String api, Map<String, dynamic>? headers,
    Map<String, dynamic> body) async {
  try {
    final request = await _httpClient.postUrl(_makeUri(api, null));
    _addHeader(request, headers);
    request.add(
      utf8.encode(
        jsonEncode(
          body,
        ),
      ),
    );
    final response = await request.close();
    if (response.statusCode == 200) {
      final responseBody = await response.transform(utf8.decoder).join();
      return json.decode(responseBody) as Map<String, dynamic>;
    }
    throw (response.statusCode);
  } catch (error) {
    rethrow;
  }
}