get method

Future<Response> get(
  1. String endpoint, {
  2. dynamic query,
})

Sends an HTTP GET request to the specified endpoint.

This method wraps the Dio GET request, providing a simplified interface. Any exceptions encountered during the request will be re-thrown.

To fetch a list of users with pagination:

try {
  final response = await apiService.get('/users', query: {'page': 1, 'limit': 10});
  print(response.data);
} on DioException catch (e) {
  print('Error fetching users: $e');
}

Parameters:

  • endpoint: The URL path or the full URL for the request (e.g., '/users').
  • query: Optional query parameters. Typically a Map<String, dynamic>.

Returns:

  • A Future<Response> that completes with the server's response.

Throws:

  • Any DioException (or other exceptions) that occur during the request.

Implementation

Future<Response> get(String endpoint, {dynamic query}) async {
  try {
    return await _dio.get(endpoint, queryParameters: query);
  } catch (e) {
    rethrow;
  }
}