insert static method

dynamic insert(
  1. String path,
  2. Object item
)

Implementation

static insert(String path, Object item) async {
  final config = CConfig();

  try {
    var result = await http.post(Uri.parse('${config.serverUrl}$path'),
        headers: {
          'Content-Type': 'application/json',
          'Authorization': 'Bearer ${config.token}'
        },
        body: jsonEncode(item));
    if (result.statusCode == 200) {
      final parsed = json.decode(utf8.decode(result.bodyBytes));
      return parsed["id"];
    }
  } catch (e) {
    if (kDebugMode) {
      print(e);
    }
  }

  return 0;
}