getService method
Services (single fetch)
GET /accounts/projects/{project_id}/services/{service_id} Returns a single Service.
Note: Some servers may return the JSON as a string payload. This method handles both a Map response and a stringified JSON.
Implementation
/// GET /accounts/projects/{project_id}/services/{service_id}
/// Returns a single Service.
///
/// Note: Some servers may return the JSON as a string payload.
/// This method handles both a Map response and a stringified JSON.
Future<ServiceSpec> getService({required String projectId, required String serviceId}) async {
final sid = Uri.encodeComponent(serviceId);
final uri = Uri.parse('$baseUrl/accounts/projects/$projectId/services/$sid');
final response = await http.get(uri, headers: _getHeaders());
if (response.statusCode >= 400) {
throw MeshagentException(
'Failed to get service. '
'Status code: ${response.statusCode}, body: ${response.body}',
);
}
final decoded = jsonDecode(response.body);
final Map<String, dynamic> json = decoded is String ? jsonDecode(decoded) as Map<String, dynamic> : decoded as Map<String, dynamic>;
return ServiceSpec.fromJson(json);
}