mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
Update RestApiUtility to allow dynamic baseURL
Modified RestApiUtility to include a method for updating the base URL dynamically. This allows the application to adapt to changes in the API's base URL without requiring a restart.
This commit is contained in:
@@ -2,12 +2,16 @@ import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class RestApiUtility {
|
||||
final String baseUrl;
|
||||
String _baseUrl;
|
||||
|
||||
RestApiUtility(this.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'));
|
||||
final response = await http.get(Uri.parse('$_baseUrl/$endpoint'));
|
||||
if (response.statusCode == 200) {
|
||||
return json.decode(response.body);
|
||||
} else {
|
||||
@@ -18,7 +22,7 @@ class RestApiUtility {
|
||||
Future<Map<String, dynamic>> post(
|
||||
String endpoint, Map<String, dynamic> payload) async {
|
||||
final response = await http.post(
|
||||
Uri.parse('$baseUrl/$endpoint'),
|
||||
Uri.parse('$_baseUrl/$endpoint'),
|
||||
body: json.encode(payload),
|
||||
headers: {"Content-Type": "application/json"},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user