Skip to content

Instantly share code, notes, and snippets.

@becek2n
Created May 8, 2020 14:23
Show Gist options
  • Save becek2n/be2503403306396d324e58024b6f2fad to your computer and use it in GitHub Desktop.
Save becek2n/be2503403306396d324e58024b6f2fad to your computer and use it in GitHub Desktop.
import 'package:http/http.dart' as http;
class APIService<T> {
final String url;// = urlHost + 'RELEASE-API/Api/attendance/getdata';
T Function(http.Response response) parse;
APIService({this.url, this.parse});
}
class APIWeb{
Future<T> load<T>(APIService<T> resource) async {
final response = await http.get(resource.url);
if(response.statusCode == 200) {
return resource.parse(response);
} else {
throw Exception('Failed to load data!');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment