post method

Future post(
  1. String endpoint, [
  2. String? json,
  3. Map<String, String>? header
])

Http client connects to the Shopify account by using the url, query and header provided here.

Implementation

Future<dynamic> post(String endpoint,
    [String? json, Map<String, String>? header]) async {
  try {
    var uri = Uri.parse(endpoint);
    var response = await http
        .post(uri, body: json, headers: header ?? baseHeader)
        .timeout(const Duration(seconds: timeOutDuration));
    if (response.statusCode >= 200 && response.statusCode < 300) {
      return response.body;
    } else {
      ///throw exception
      _handleResponse(response);
    }
  } on SocketException {
    /// FetchData Exception is thrown on Socket Exception
    throw FetchDataException('No internet connection');
  } on TimeoutException {
    /// Api Not Responding Exception exception is thrown on Timeout Exception
    throw ApiNotRespondingException('Api not responding');
  }
}