Recipe and Diet apps usage has been growing rapidly over the past few years. As per one study, revenue in the Nutrition Apps segment is estimated to reach $ 4285.69m in 2021 and is expected to reach $10,891m by 2027. One of the major contributing factors to this surge can be attributed to the Coronavirus pandemic. While the world battles with lockdown, closure of restaurants, and physical distancing guidelines – people have started cooking more at home. Home cooking has become the new norm. Research finds that more than 55% of shoppers are eating at home more often since the pandemic began.
Many companies and application developers are now turning their attention towards Recipe and Diet applications. However, developing such an app would require a lot of effort, considering that users have their own unique food and diet preferences.
Recipe Search and Diet API solves this problem by providing programmatic access to over 2 million recipes. It also provides access to over 5000 top web recipe sources and contains useful data such as ingredients, diets, allergies, nutrition, taste, techniques, etc. The API is freemium and the basic plan imposes a hard limit of 1000 requests per month.
Note: If you are new to the APIs, please go through this article first before we dive into further details.
What is Recipe Search and Diet API?
Recipe Search and Diet API is a Rest API that allows developers to search through the semantically organized database of 2 million recipes. Users can provide any keyword such as ‘chicken’ or ‘keto’ and the API will return the list of most popular and best recipes.
In addition, it provides a comprehensive nutrition breakdown of each recipe, which is powered by a Natural Language Processing (NLP) engine, in order to produce the most accurate nutrition analysis for all the recipes.
The API also provides the diet recommendation through ‘health labels’ and cautions data fields, making it easier for developers to create personalized diet plans based on users’ preferences, allergies, and tastes. It can be integrated in a seamless manner with various languages and platforms using its single endpoint.
How Recipe and Diet API Works
The Recipe Search and Diet API conforms to REST principles and provides an endpoint that can be executed over the web using the HTTP GET method. The GET request can be sent using any programming language.
The API uses the following mechanism to entertain requests. The Client application executes the endpoint by providing required parameters for recipes or recommendations. The API Server processes the request using its NLP engine and Recipe database in order to select the best matches for the given keywords. The response is then semantically organized and formatted into JSON before sending it back to the client.
The Client application, with the help of SDK, parse the JSON response to extract the needed information such as recipe source, diet and nutrition information, various labels, etc.
The below diagram illustrates the high-level overview of the Recipe Search and Diet API.
How to Connect to Recipe Search and Diet API
In the following section, we will cover how to connect to Recipe Search and Diet API using the RapidAPI platform.
Step1: Signup for an Account on RapidAPI
First, you need to create an account on RapidAPI (where you can find and connect to thousands of APIs using one SDK and one API Key).
Step2: Search the API Marketplace
After successful registration, you will be redirected to the dashboard. Navigate to “API Marketplace” and search for “Recipe Search and Diet API”.
Select the second item from the result set with the title “Recipe Search and Diet” as shown below. It will redirect you to the API dashboard.
Step3: Test the Recipe and Search API
In the final step, we will execute the Recipe Search and Recommendation endpoint by navigating to the ‘Endpoints’ tab.
You can notice the required parameters such as API Key and Host have already been generated by RapidAPI.
To execute the endpoint you need to provide the search parameters and the API will return the list of recipes along with its nutritional data.
For instance, the below example invoked the API for the ‘keto’ diet and we can see from the below image that the API has successfully returned the results.
Note: In case of any failure, the Recipe and Search API may return one of the following responses:
- 400 Bad Request – Client sent an invalid request (missing required parameters).
- 401 Unauthorized – Failed to authenticate with the API server.
- 403 Forbidden – The client authenticated but didn’t have permission to access the required resource.
- 404 Not Found – The requested resource (endpoint) doesn’t exist.
- 500 Internal Server Error – A generic error occurred on the API server.
- 503 Service Unavailable – The API service is not available.
If the API couldn’t find the information about the given query or the parameters were not provided – it will return the empty JSON response.
Explanation of the Recipe Search and Diet API
It has a single endpoint called ‘Recipe Search and Recommendations’ which allows the user to fetch the list of recipes for any given keyword. Each recipe contains a complete nutrition breakdown, diet labels, health labels, ingredients, type of cuisine, total nutrients, total daily percentage, and cautions.
For instance, executing the endpoint with the query parameter ‘chicken’ will produce the following response.
The response is formatted as JSON and contains the array of recipes in a variable called ‘hits’.
Let’s drill down the result set in order to understand the recipe object.
The recipe object has 21 items that can be summarized as below:
Uri | Edamam search URI |
label | Name of the recipe |
image | Thumbnail image of the recipe |
source | Recipe Source name |
Url | Recipe source website |
shareas | Edamam recipe summary page |
dietLabels | This is an array that contains various diet labels for the recipe such as “low-carb”,”high-protein” etc |
healthlabels | This array contains the health label for the selected recipe, such as ‘peanut-free’, ‘gluten-free’ etc. |
cautions | This variable contains if the recipe has any allergen warning |
ingredientLines | This array contains the list of ingredients with serving size and instructions |
ingredients | This array also contains the list of ingredients but it separates the text, weight, food category, food id, and image as separate variables |
calories | This field contains the total calories for the recipe |
totalWeight | Total weight of the whole recipe |
Totaltime | The time it would take to cook the recipe |
cusineType | It represents the type of cuisine such as Chinese, American, etc |
mealType | Lunch/dinner |
dishType | Such as the main course, starters, and desserts. |
totalNutrients | This array contains the complete breakdown of the recipe for 32 nutrients. |
totalDaily | This array also contains the nutritional breakdown with respect to the percentage of daily consumption. |
digest | This contains macros information such as protein, carbohydrates, fats along with the vitamins, minerals, and water content. |
In the following section, we will see how to use Recipe Search and Diet API using various languages such as Python, PHP, Ruby, and JavaScript. We will use the RapidAPI dashboard to generate the code snippets.
How to use Recipe Search and Diet API with Python
Before running the following code, make sure that you have installed the Python application.
The below example uses http.client library to execute the endpoint with search parameter ‘steak’
import http.client conn = http.client.HTTPSConnection("edamam-recipe-search.p.rapidapi.com") headers = { 'x-rapidapi-host': "edamam-recipe-search.p.rapidapi.com", 'x-rapidapi-key': "ce19d0164fmsh3d383efc0e85ce5p16dcb1jsnb1a4a3c79541" } conn.request("GET", "/search?q=chicken", headers=headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8"))
The API successfully returned the response as shown below.
How to use Recipe Search and Diet API with PHP
The below example uses PHP’s $curl function to execute the recipe search and recommendation endpoint with the keyword ‘steak’. Once the code is generated, we can click on ‘Test Endpoint’ to execute the request.
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://edamam-recipe-search.p.rapidapi.com/search?q=steak", 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-recipe-search.p.rapidapi.com", "x-rapidapi-key: ce19d0164fmsh3d383efc0e85ce5p16dcb1jsnb1a4a3c79541" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
How to use Recipe Search and Diet API with Ruby
Make sure that you have installed Ruby in your system before testing the following code snippet.
The below example also executes the recipe search and recommendation endpoint with the keyword ‘steak’.
require 'uri' require 'net/http' require 'openssl' url = URI("https://edamam-recipe-search.p.rapidapi.com/search?q=steak%20") 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-host"] = 'edamam-recipe-search.p.rapidapi.com' request["x-rapidapi-key"] = 'ce19d0164fmsh3d383efc0e85ce5p16dcb1jsnb1a4a3c79541' response = http.request(request) puts response.read_body
The API successfully returned the response containing the list of most popular steak recipes.
How to use Recipe Search and Diet API with JavaScript
To use the API in JavaScript, you need to first set up the JavaScript environment. You can download text editors such as Atoms, Visual Studio Code, NotePad++, etc.
The following code snippet demonstrates how to fetch a list of recipes using the keyword “steak”.
fetch("https://edamam-recipe-search.p.rapidapi.com/search?r=protien%20", { "method": "GET", "headers": { "x-rapidapi-host": "edamam-recipe-search.p.rapidapi.com", "x-rapidapi-key": "ce19d0164fmsh3d383efc0e85ce5p16dcb1jsnb1a4a3c79541" } }) .then(response => { console.log(response); }) .catch(err => { console.error(err); });
The endpoint has been successfully executed as shown below.
Benefits
Recipe Search and Diet API not only focuses on providing the most popular recipes but also takes diet and nutrition into consideration by providing a complete nutritional breakdown which is essential for any diet plan. Some of the other benefits can be summarized as below.
Speed
The Recipe Search and Diet API can search through the database of 2 million recipes in less than a second. Developers building high performant applications can rely on this API without worrying about the latency issues that come with integrating third-party APIs.
AI-Powered Engine
It’s powered by an NLP recommendation engine which helps users to get the most accurate automated nutrition analysis and build applications for any popular diet or health condition.
Reliability
API consumers are often developers who build applications atop a service that they can trust. Recipe Search and Diet API has 100% Service Level – meaning all the calls made to the API within the last 30 days were successful.
Alternatives to Recipe Search and Diet API
Below are some alternatives to the Recipe Search and Diet API.
- Recipe-Food-Nutrition API: This API allows you to access over 365,000 recipes and 86,00 food products. It has several endpoints for recipe and nutrition.
- Recipe API: This is a freemium API and has paid plans for various request quotas. It has over 330,000 recipes in its database.
- BigOven API: This API has several endpoints and allows you to access over 350,000 recipes, reviews, and nutrition facts.
- Recipe Puppy: It’s a free and simple API that lets you search through the database of over a million recipes.
Summary
In this article, we have explored how Recipe Search and Diet API can be used to create a variety of solutions in the food and nutrition domain. We have also discussed in detail how to connect to it using the RapidAPI platform and generate code snippets in popular programming languages.
Leave a Reply