workouttest_app/lib/service/api.dart
2020-05-24 10:04:37 +02:00

28 lines
885 B
Dart

import 'dart:convert';
import 'package:http/http.dart' as http;
class APIClient {
final String _baseUrl = 'http://andio.eu:8888/api/';
Future<String> get(String endPoint, String param) async {
final url = _baseUrl + endPoint + param;
final response = await http.get(url, headers: {'Content-Type': 'application/json'});
if(response.statusCode == 200) {
return utf8.decode(response.bodyBytes);
} else {
throw Exception("Unable to perform HTTP request!");
}
}
Future<String> post(String endPoint, String body) async {
final url = _baseUrl + endPoint;
print(" ------------ http/post endpoint $endPoint body $body");
final response = await http.post(url,
headers: {'Content-Type': 'application/json'},
body: body
);
print(" ------------ response: " + response.body.toString());
return response.body;
}
}