postToDB function

Future<Map> postToDB({
  1. required String api,
  2. required String apiKey,
  3. required Map<String, dynamic> body,
  4. Map<String, String>? headers,
})

helper methods for http requests TODO: Map httpCalls to Singleton Class Generic Post function to make Post API calls

Implementation

///Generic Post function to make Post API calls
Future<Map> postToDB(
    {required String api,
    required String apiKey,
    required Map<String, dynamic> body,
    Map<String, String>? headers}) async {
  final http.Response response = await http.post(
    Uri.parse(api),
    headers: {
      'Content-Type': 'application/json',
      'X-CC-Version': '2018-03-22',
      'X-CC-Api-Key': apiKey,
    },
    body: jsonEncode(body),
  );
  return jsonDecode(response.body);
}