getRoute method

Future<Route> getRoute({
  1. required String projectId,
  2. required String domain,
})

GET /accounts/projects/{project_id}/routes/{domain}

Implementation

Future<Route> getRoute({required String projectId, required String domain}) async {
  final encodedProjectId = Uri.encodeComponent(projectId);
  final encodedDomain = Uri.encodeComponent(domain);
  final uri = Uri.parse('$baseUrl/accounts/projects/$encodedProjectId/routes/$encodedDomain');
  final response = await httpClient.get(uri);

  if (response.statusCode == 404) {
    throw NotFoundException('Route not found: $domain');
  }

  if (response.statusCode >= 400) {
    throw MeshagentException(
      'Failed to get domain.'
      'Status code: ${response.statusCode}, body: ${response.body}',
    );
  }

  final data = jsonDecode(response.body) as Map<String, dynamic>;
  return Route.fromJson(data["route"] as Map<String, dynamic>);
}