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

Implementation

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),
  );
  print(response.body);
  return jsonDecode(response.body);
}