loadFromRemote method
Loads gate configuration from a remote endpoint via HTTP GET.
Expects a JSON response matching FeatureGateConfig.fromJson format.
Implementation
Future<FeatureGateConfig> loadFromRemote(String endpoint) async {
final client = HttpClient();
try {
final request = await client.getUrl(Uri.parse(endpoint));
if (_organizationId != null) {
request.headers.set('X-Organization-Id', _organizationId!);
}
final response = await request.close();
if (response.statusCode != 200) {
throw HttpException(
'Failed to load feature gates: HTTP ${response.statusCode}',
);
}
final body = await response.transform(utf8.decoder).join();
final json = jsonDecode(body) as Map<String, dynamic>;
final config = FeatureGateConfig.fromJson(json);
_applyConfig(config);
return config;
} finally {
client.close();
}
}