Added Nextcloud base

This commit is contained in:
2023-02-20 10:56:51 +01:00
parent e54ae9c2ff
commit fea36b9a6d
63 changed files with 1863 additions and 700 deletions

View File

@ -4,36 +4,5 @@ import 'package:http/http.dart' as http;
import 'package:marianum_mobile/api/apiError.dart';
class ApiRequest {
Uri endpoint;
ApiRequest(this.endpoint);
Future<http.Response> get(Map<String, String>? headers) async {
return await http.get(endpoint, headers: headers);
}
Future<http.Response> post(String data, Map<String, String>? headers) async {
log("Fetching: ${data}");
try {
http.Response response = await http
.post(endpoint, body: data, headers: headers)
.timeout(
const Duration(seconds: 10),
onTimeout: () {
log("timeout!");
throw ApiError("Network timeout");
}
);
if(response.statusCode != 200) {
log("Got ${response.statusCode}");
throw ApiError("Service response invalid, got status ${response.statusCode}");
}
return response;
} on Exception catch(e) {
throw ApiError("Http: ${e.toString()}");
}
}
}