invoke method

Future invoke(
  1. String path, {
  2. String body = '',
})

Implementation

Future<dynamic> invoke(String path, {String body = ''}) {
  final url = Uri.parse('$urlApi/$path');

  return http
      .post(
        url,
        headers: {
          'accept': '*/*',
          'Content-Type': 'application/json',
          'Authorization': 'Bearer $token'},
        body: body,
      )
      .then((response) {
        if (response.statusCode == 200) {
          return jsonDecode(response.body);
        } else {
          if (kDebugMode) {
            print('Failed to invoke: ${response.statusCode}');
          }
          throw Exception('Failed to invoke');
        }
      });
}