post method

  1. @override
Future<HttpResponse> post(
  1. String url,
  2. Map<String, Object?> data
)
override

POST request

url is the full URL for the API. data is the body to be sent with the request.

Implementation

@override
Future<HttpResponse> post(
  String url,
  Map<String, Object?> data,
) {
  return _handleExceptions(
    () async {
      final uri = Uri.parse(url);
      final response = await _client.post(
        uri,
        body: data,
        headers: KhaltiService.config.raw,
      );
      final statusCode = response.statusCode;
      final responseData = jsonDecode(response.body);

      if (_isStatusValid(statusCode)) {
        return HttpResponse.success(
          data: responseData,
          statusCode: statusCode,
        );
      }
      return HttpResponse.failure(
        data: responseData,
        statusCode: statusCode,
      );
    },
  );
}