X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=flempires%2Flib%2FWebService.dart;fp=flempires%2Flib%2FWebService.dart;h=d189a4ededd065a09021de1d9a9756f1a7098e92;hb=d977a912c29fa640d2fba5b5774dbf31dd34e417;hp=0000000000000000000000000000000000000000;hpb=66b2a746709b394b60ae653afc9408e5215d879f;p=lmno.games diff --git a/flempires/lib/WebService.dart b/flempires/lib/WebService.dart new file mode 100644 index 0000000..d189a4e --- /dev/null +++ b/flempires/lib/WebService.dart @@ -0,0 +1,23 @@ +import 'package:http/http.dart' as http; +import 'package:http/http.dart'; + +class Request { + final String url; + T Function(Response response) parse; + final String type; + + Request({this.url, this.parse, this.type}); +} + +class WebService { + Future fetch(Request request) async { + final response = await http.get(request.url); + + if (response.statusCode == 200) { + return request.parse(response); + } else { + throw Exception( + 'Failed to fetch ' + request.type + ' from url ' + request.url); + } + } +}