Have you ever felt the need to look up calories and other nutrient information for a particular food product? The Edamam Food and Grocery Database API can come to your rescue!
Health and well-being have been gaining increasing attention in today’s world. More and more people around the world are growing concerned about their well being. They are educating themselves to stay fit and adopt a healthier lifestyle. With this increase in awareness pertaining to their health, people are showing greater interest towards knowing the micro and macro constituents of the food they consume. Knowing the number of calories in the food they eat, along with their nutrient constituents, arms the consumers with information to make better decisions and significantly improve their eating habits. This has led to the manifestation of numerous applications and services in the health and nutrition space that seek to inform and educate their end users.
The Edamam suite of diet and nutrition APIs seeks to enable and equip its end users with relevant information specific to food products, to help make better choices, and consequently improve their overall well-being and lifestyle. Popular APIs from Edamam in the nutrition and health space include – recipe search, food database, and nutrition analysis.
In this article, we will be discussing the Edamam Food and Groceries Database API. The API has been developed in response to the strong interest in basic nutrition information exhibited by the masses. The objective of the API has been to provide an affordable medium of accurate nutrient related information, for its users in order to facilitate and inculcate better eating habits and a healthier lifestyle.
What is the Edamam Food and Grocery Database API?
The Edamam Food and Grocery Database API is a REST based API service for looking up nutrition and diet related data for food products. The API empowers its users with nutrition and diet data for generic foods, packaged foods and restaurant meals. It supports searching a food item by keyword, its name or UPC/Barcode. The API provides the end user with nutritional details for the input food item such as – macro and micro nutrients, and labels including – allergen, lifestyle and health. It also supports searching for food items within a given brand name. Additionally, it leverages Natural Language Processing (NLP) for named entity recognition to recognize food entities from unstructured natural language text. This component is particularly useful in the context of food-logging for calorie-counting.
How does the Edamam Food and Grocery Database API work?
The Edamam Food and Grocery Database API takes the food item to look up as the input and returns nutrition and diet-related information pertaining to the input food item as the output. The information includes nutritional constituents of the food in addition to meticulously tagged labels associated with the input food item.
The API also supports unstructured natural language text as input for users who use chatbots for food-logging. This support is facilitated by leveraging Natural Language Processing (NLP) under its hood, for food entity recognition in the unstructured natural language text. The API supports searching for data on common food items purchased in stores, ordered in restaurants or cooked at home. The API also facilitates searching for food items by brand in addition to support for twenty eight nutrients in the search results.
Who is the Edamam Food and Grocery Database API for exactly?
The Edamam Food and Grocery Database API is intended to serve application developers and web developers and also startups and enterprises – who are looking to integrate an efficient and easy to use food database lookup feature in their application or website. The API primarily caters to developers of apps and services in the nutrition, health, well-being, diet management and weight loss space. The API is free for developers and pre-revenue startups.
How to connect to the Edamam Food and Grocery Database API Tutorial
The following is a step-by-step tutorial for connecting to the Edamam Food and Grocery Database API.
Step 1: Sign Up on RapidAPI
A RapidAPI account is required to connect to the Edamam Food and Grocery Database API. You can sign up for a RapidAPI account by navigating to the RapidAPI website and clicking on the Sign-Up button at the top right!
RapidAPI supports signing up using Google, Github, or Facebook.
Step 2: Testing Connection to the Edamam Food and Grocery Database API
Having signed up and logged in to RapidAPI, you would need to navigate to the Edamam Food and Grocery Database API page on the RapidAPI platform to connect to the API.
To test API connection, please click on the “Test Endpoint” button. A successful connection would result in a “200 OK” response in the Results tab on this page.
Now that you have connected and tested the connection to the Edamam Food and Grocery Database API, let’s learn more about its usage!
Endpoint of the Edamam Food and Grocery Database API
The Edamam Food and Grocery Database API has one endpoint “parser
” to facilitate lookup for food items. The endpoint with the relevant information on its usage is as follows:
The Parser Endpoint: The endpoint returns the nutrient content, labels and other relevant information based on the parameters requested by the user.
The parameters supported by the API for sending a request to the endpoint are as follows:
ingr
– This refers to the keyword search parameter to be found in the food name. This is not required when theupc
parameter is present. This parameter also supports unstructured natural language text containing the food name to be queried.upc
– This refers to the valid UPC code corresponding to the food product to be queried. This is not required when theingr
parameter is present.
The API response contains a list of nutrients with their corresponding values in addition to relevant labels for the user input food product.
How to use the Edamam Food and Grocery Database API with Python?
The following code snippet depicts the use of Edamam Food and Grocery Database API with Python. It uses the “requests” library to send a GET request to the endpoint with the parameter specified in the “querystring” dictionary.
The “x-rapidapi-key
” value in the “headers” dictionary would need to be replaced with your actual key which can be obtained from the Edamam Food and Grocery Database API page in the Header Parameters section.
import requests url = "https://edamam-food-and-grocery-database.p.rapidapi.com/parser" querystring = {"ingr":"apple"} headers = { 'x-rapidapi-key': "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 'x-rapidapi-host': "edamam-food-and-grocery-database.p.rapidapi.com" } response = requests.request("GET", url, headers=headers, params=querystring) print(response.text)
How to use the Edamam Food and Grocery Database API with PHP?
The following code snippet depicts the use of Edamam Food and Grocery Database API with PHP. It uses the “curl” function of PHP to send a GET request to the endpoint with the parameter specified in the “CURLOPT_URL”.
The “x-rapidapi-key
” value in the “CURLOPT_HTTPHEADER” object would need to be replaced with your actual key which can be obtained from the Edamam Food and Grocery Database API page in the Header Parameters section.
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://edamam-food-and-grocery-database.p.rapidapi.com/parser?ingr=apple", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "x-rapidapi-host: edamam-food-and-grocery-database.p.rapidapi.com", "x-rapidapi-key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
How to use the Edamam Food and Grocery Database API with Ruby?
The following code snippet depicts the use of Edamam Food and Grocery Database API with Ruby. The “x-rapidapi-key
” value in the “request” object would need to be replaced with your actual key which can be obtained from the Edamam Food and Grocery Database API page in the Header Parameters section.
require 'uri' require 'net/http' require 'openssl' url = URI("https://edamam-food-and-grocery-database.p.rapidapi.com/parser?ingr=apple") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-key"] = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' request["x-rapidapi-host"] = 'edamam-food-and-grocery-database.p.rapidapi.com' response = http.request(request) puts response.read_body
How to use the Edamam Food and Grocery Database API with JavaScript?
The following code snippet depicts the use of Edamam Food and Grocery Database API with JavaScript. It uses JQuery’s “ajax” function to send a GET request to the endpoint with the parameters specified in the “settings” object.
The “x-rapidapi-key
” value in the “headers” object would need to be replaced with your actual key which can be obtained from the Edamam Food and Grocery Database API page in the Header Parameters section.
const settings = { "async": true, "crossDomain": true, "url": "https://edamam-food-and-grocery-database.p.rapidapi.com/parser?ingr=apple", "method": "GET", "headers": { "x-rapidapi-key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "x-rapidapi-host": "edamam-food-and-grocery-database.p.rapidapi.com" } }; $.ajax(settings).done(function (response) { console.log(response); });
Alternatives to the Edamam Food and Grocery Database API
A few alternatives APIs that provide food lookup capabilities similar to the Edamam Food and Grocery Database API are:
- CalorieNinjas
- This API provides nutritional data for queried food items from natural language text.
- Yummly
- This API supports querying for recipes, diet plan and ingredients of the input food item.
- Food Calorie Data Search
- This API enables searching for calorie details based on food names.
- Tasty
- This API facilitates searching for ingredients and recipes based on input text.
Benefits of the Edamam Food and Grocery Database API
The Edamam Food and Grocery Database API empowers its users by providing nutrition related information in addition to tagging relevant and useful labels for the user queried food item. The API has a rich database under its hood that includes generic foods, packaged foods, home-cooked foods and also restaurant meals. This facilitates searching a food item by keyword, its name, brand or UPC/Barcode. Additionally, the use of Natural Language Processing (NLP) technology for named entity recognition to recognize food entities, enables support for chatbot based applications that provide food-logging service for calorie counting.
Summary
The Edamam Food and Grocery Database API is a powerful tool for app and web developers, looking for seamless integration of an efficient and easy to use food database lookup feature in their application or website. The API thus enables its users to search for food items and returns relevant nutrition information specific to the user input food products. The API thus caters to developers and enterprises working in the domain of nutrition, diet management and weight loss, towards facilitating well-being and better lifestyle for their customers.
Leave a Reply