Unable to retrieve data from RapidAPI in Flutter app

I’m facing an issue with loading data in my Flutter application. While it works fine when I retrieve data from a standard JSON endpoint, like https://jsonplaceholder.typicode.com/albums, I’m unable to fetch any data when using RapidAPI. I’m unsure if this is due to a server connection issue or an error in my setup.

If anyone has encountered similar challenges with RapidAPI, I would appreciate your insights.

Here’s my code for reference:

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

Future<List<RecipeData>> loadRecipeData() async {
  var endPoint = Uri.https('yummly2.p.rapidapi.com', '/feeds/list',
      {"limit": "18", "start": "0", "tag": "list.recipe.popular"});

  final response = await http.get(endPoint, headers: {
    "x-rapidapi-key": "your_api_key_here",
    "x-rapidapi-host": "yummly2.p.rapidapi.com",
    "useQueryString": "true"
  });

  if (response.statusCode == 200) {
    List jsonResponse = json.decode(response.body);
    return jsonResponse.map((item) => RecipeData.fromJson(item)).toList();
  } else {
    throw Exception('Failed to load recipes');
  }
}

class RecipeData {
  final String title;

  RecipeData({required this.title});

  factory RecipeData.fromJson(Map<String, dynamic> json) {
    return RecipeData(
      title: json['name'],
    );
  }
}

Been there with RapidAPI - so frustrating! Check your request headers first. Some APIs get weird about User-Agent or want specific Content-Type even for GET requests. That “useQueryString” header should be boolean, not a string. Try dropping it completely and see what happens. Also caught me off guard - some RapidAPI endpoints use different base URLs than their docs show. Double-check you’re hitting the right host. When I moved from free APIs to RapidAPI, the auth flow tripped me up too. Make sure your subscription’s active and you haven’t maxed out usage limits.

The Yummly API doesn’t return what you’re expecting. The feeds/list endpoint gives you an object with a ‘feed’ property - that’s where the actual recipe array lives. It’s not a direct array like jsonplaceholder. You’ll need to update your parsing logic for this nested structure. Also double-check you’re using the right response field for the title - probably ‘display’ or ‘content’, not ‘name’. I ran into the same thing switching from simple REST APIs to RapidAPI. Their response formats are way more complex than standard JSON APIs.

make sure your api key is still working, sometimes they just expire or hit limits. try printing the full response body and the status code - that really helps with debugging!