Added PUT method support to RestApiUtility

Enhanced the RestApiUtility class to support HTTP PUT requests. The new method, `put`, allows for updating data at a specified endpoint. This addition provides more comprehensive CRUD operations for the API interactions, ensuring the client can perform updates when necessary.
This commit is contained in:
hunteraraujo
2023-09-27 00:12:17 -07:00
parent dc4ca47bc7
commit 5f4454737d

View File

@@ -54,6 +54,24 @@ class RestApiUtility {
}
}
Future<Map<String, dynamic>> put(
String endpoint, Map<String, dynamic> payload,
{ApiType apiType = ApiType.agent}) async {
final effectiveBaseUrl = _getEffectiveBaseUrl(apiType);
final response = await http.put(
Uri.parse('$effectiveBaseUrl/$endpoint'),
body: json.encode(payload),
headers: {"Content-Type": "application/json"},
);
if (response.statusCode == 200 || response.statusCode == 201) {
return json.decode(response.body);
} else {
print(response.statusCode);
print(response.body);
throw Exception('Failed to update data with PUT request');
}
}
Future<Uint8List> getBinary(String endpoint,
{ApiType apiType = ApiType.agent}) async {
final effectiveBaseUrl = _getEffectiveBaseUrl(apiType);