putData<T> function
Generic PUT request
Implementation
Future<T> putData<T>({
required String endpoint,
required Map<String, dynamic> body,
T Function(dynamic json)? fromJson,
}) async {
if (_baseUrl.isEmpty) {
throw Exception("Base URL is not set. Call setBaseUrl() first.");
}
final response = await http.put(
Uri.parse("$_baseUrl/$endpoint"),
headers: _buildHeaders(),
body: jsonEncode(body),
);
if (response.statusCode == 200) {
final json = jsonDecode(response.body);
return fromJson != null ? fromJson(json) : json;
} else {
throw Exception("PUT $endpoint failed: ${response.statusCode}");
}
}