postRequest method

dynamic postRequest({
  1. required dynamic body,
  2. required String request,
  3. required String baseUrl,
  4. required String consumerKey,
  5. required String consumerSecret,
})

Implementation

postRequest(
    {required body,
    required String request,
    required String baseUrl,
    required String consumerKey,
    required String consumerSecret}) async {
  final response = await http.post(
    Uri.parse(baseUrl + request),
    headers: {
      'Content-Type': 'application/json',
      'Authorization':
          'Basic ${base64Encode(utf8.encode('$consumerKey:$consumerSecret'))}',
    },
    body: body,
  );

  // Check if the request was successful (status code 201)
  if (response.statusCode == 201) {
    return response;
  } else {
    throw Exception(
        'Error -: Failed to Complete Request : ${json.decode(response.body)}');
  }
}