mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-18 14:34:23 +01:00
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:
@@ -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,
|
Future<Uint8List> getBinary(String endpoint,
|
||||||
{ApiType apiType = ApiType.agent}) async {
|
{ApiType apiType = ApiType.agent}) async {
|
||||||
final effectiveBaseUrl = _getEffectiveBaseUrl(apiType);
|
final effectiveBaseUrl = _getEffectiveBaseUrl(apiType);
|
||||||
|
|||||||
Reference in New Issue
Block a user