Merge commit 'e5d30a9f6d0854e20049309333c2f637cd03025c' as 'frontend'

This commit is contained in:
hunteraraujo
2023-09-06 11:22:37 -07:00
165 changed files with 7133 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
class RestApiUtility {
String _baseUrl;
RestApiUtility(this._baseUrl);
void updateBaseURL(String newBaseURL) {
_baseUrl = newBaseURL;
}
Future<Map<String, dynamic>> get(String endpoint) async {
final response = await http.get(Uri.parse('$_baseUrl/$endpoint'));
if (response.statusCode == 200) {
return json.decode(response.body);
} else {
throw Exception('Failed to load data');
}
}
Future<Map<String, dynamic>> post(
String endpoint, Map<String, dynamic> payload) async {
final response = await http.post(
Uri.parse('$_baseUrl/$endpoint'),
body: json.encode(payload),
headers: {"Content-Type": "application/json"},
);
if (response.statusCode == 200 || response.statusCode == 201) {
return json.decode(response.body);
} else {
throw Exception('Failed to post data');
}
}
}