Created
May 29, 2019 18:02
-
-
Save azamsharp/8cccdcb20d825c06261e21c51d3ec251 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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