testGetRequest static method

Future testGetRequest()

Test GET API request

Implementation

static Future<dynamic> testGetRequest() async {
  final environment = createTestEnvironment();
  final endpoint = GtdEndpoint(env: environment, path: 'posts');

  // Configure the network service with a GET request
  final networkService = GtdNetworkService.shared;
  networkService.request = GTDNetworkRequest(
    type: GtdMethod.get,
    enpoint: endpoint,
    queryParams: {
      'userId': 1, // Optional filter
    },
  );

  try {
    // Execute the GET request
    final response = await networkService.execute();

    print('GET request successful: ${response.statusCode}');
    print('Response data (first item): ${response.data[0]}');
    return response.data;
  } on DioException catch (e) {
    print('GET request failed: ${e.message}');
    rethrow;
  }
}