Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Created May 29, 2019 18:02
Show Gist options
  • Save azamsharp/8cccdcb20d825c06261e21c51d3ec251 to your computer and use it in GitHub Desktop.
Save azamsharp/8cccdcb20d825c06261e21c51d3ec251 to your computer and use it in GitHub Desktop.
import 'package:http/http.dart' as http;
import 'package:http/http.dart';
class Resource<T> {
final String url;
T Function(Response response) parse;
Resource({this.url,this.parse});
}
class Webservice {
Future<T> load<T>(Resource<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