0

I am currently trying to learn rest APIs. I want to program a food app and I'm using the Edamam food database. https://developer.edamam.com/food-database-api-docs

If I do a request on the browser with a sample link:

https://api.edamam.com/api/food-database/v2/parser?app_id="myOwnAppId"&app_key="myOwnAppKey"&ingr=apple&nutrition-type=cooking.

Then I also get a response and all the data in JSON format.

But in Flutter I only get an error and no data output.

The code:

getFoods(String query) async { String url = "api.edamam.com";

var response = await http.get(Uri.https("api.edamam.com",
    "/api/food-database/v2/parser?app_id=$appID&app_key=$appKey&ingr=$query&nutrition-type=cooking"));

print(response.body); //Output{"status" : "error", "message" : null }

}

What am I doing wrong?

I think the problem is the second parameter in Uri.https()? i don't know what should go in there

Anima361
  • 31
  • 5
  • try this once `var headers = {"Content-type": "application/json"};` `var res = await http.get(YOUR_WHOLE_URL, headers: headers); ` – Manish Aug 30 '21 at 15:57
  • Yeah I got it now. I understood the headers. This is what I need: var response = await http .get(Uri.https("api.edamam.com", "/api/food-database/v2/parser", { "app_id": "$appID", "app_key": "$appKey", "ingr": "$query", "nutrition-type": "cooking", })); – Anima361 Aug 30 '21 at 18:57

0 Answers0