Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
September 10, 2022 12:01 pm

Analyze Recipes and Nutrition With APILayer Food APIs


Few things affect our lives more than food. It’s a daily ritual that we take part in for a variety of reasons. Eating a meal with friends and family is the highlight of many people’s day. But more than that, food is the primary vehicle we use to get the nutrients our bodies need to survive. 





And yet, food can also negatively impact our health. For example, consuming too much food usually results in weight gain and its related health issues. Then there are allergies to certain foods that, when consumed, can cause someone to become very ill or die. This is why it's so important for people to get accurate nutritional information about the food they eat. 


The invention of the Internet obviously changed the way people get information. Regardless of what application you’re building, be it web, mobile, or even desktop, the food-based APIs from APILayer and Edamam can empower your applications to provide users with the accurate nutritional information they need. 


What Are APILayer and Edamam?


APILayer specializes in building web-based APIs. They’ve built dozens of API products that are used by large corporations and millions of people, and in order to handle such a high level of load and demand, they built an infrastructure that is fast, scalable, and reliable. Not only do they run their own APIs on their infrastructure, but they run other companies’ APIs and make them available via the APILayer Marketplace. Edamam’s nutrition-oriented APIs are some of those.


Edamam is the leading provider of nutritional data and analytics, and they aim to capture the world’s food knowledge and break it down to help people make informed decisions at the store, restaurant, and in the kitchen.


There are three Edamam APIs in the APILayer Marketplace:


The Nutrition Analysis API—submit the full text of any recipe or just a single ingredient to retrieve the nutritional contents. 


The Food and Grocery Database API—access Edamam’s food and grocery database, which contains 900,000 basic foods, restaurant items, and consumer packaged foods. Filter them by diet and other health filters generated by Edamam. 


The Recipe Search API—search Edamam’s large recipe database that contains 2.3 million recipes and their nutritional content.


Features: Why Use the APILayer Food APIs?


If you are building food- and nutrition-based applications, then you want to provide your users with the most accurate nutritional information available. APILayer Food APIs can do just that because of the following features:


Natural Language Processing


APILayer Food APIs use natural language processing. This means that your users don’t need to use special words or jargon to get the nutritional information they want. 


Full Nutritional Analysis


Regardless of whether your users want the nutritional information for a single food item or ingredient or a full recipe, APILayer Food APIs provides the full nutritional analysis, including diet, allergy, and health labels.


Ginormous Edamam Food Database


Edamam’s food database consists of 900,000 basic foods, restaurant items, and consumer packaged foods. No matter what foods your users search for, chances are very good Edamam has the nutritional information for them.


Huge Recipe List


Your users can search for 2.3 million recipes and filter the results based on diet, calories, and other health filters—including chronic conditions such as Type 2 diabetes, kidney disease, and more.


Accurate Nutritional Data


Edamam strives to provide the world with the most accurate nutritional information available. 


Highly Scalable


The Food APIs run on APILayer’s cloud infrastructure, and it can meet your smallest and largest demands (as well as everyone else’s). 


Unparalleled Speed


Your users will get their results in the blink of an eye because of APILayer’s lightning-fast infrastructure. 


Near 100% Uptime


While nothing is 100%, the uptime for APILayer’s services is as close as it gets.


How It Works 


Getting started with the APILayer Food APIs is fast and easy. First, you need to create an APILayer account. You don’t need multiple accounts to use multiple APIs. One account gives you access to all APILayer APIs, but you need an application ID and authentication key to successfully make requests.


APILayer dashboardAPILayer dashboardAPILayer dashboard

To create an application, visit your account’s dashboard and click the Applications tab. There, you can create an application and choose which API that application will access. 


create application in APILayercreate application in APILayercreate application in APILayer

After you create your application, you can view its details to retrieve the application ID and authentication keys.


retrieve the application ID and authentication keys.retrieve the application ID and authentication keys.retrieve the application ID and authentication keys.

Quick Tutorial


APILayer allows you to make requests from any viable HTTP client, including JavaScript running inside the browser. For this tutorial, we’ll use vanilla JavaScript and the Fetch API to request data from the Nutrition Analysis API.


You can use the Nutrition Analysis API to request data either for individual ingredients or for entire recipes. In this tutorial, we’ll make a request for a single ingredient. To do so, we need to issue a GET request to https://api.edamam.com/api/nutrition-data and supply the following query parameters:




  • app_id: our application’s ID 


  • app_key: our application’s authentication key


  • ingr: the ingredient to query


The Fetch API makes it easy to send GET requests with query parameters. First, create a new URLSearchParams object like this:



This code initializes a URLSearchParam object with the necessary query parameters and their values. Next, call fetch() and pass it the URL and params, as shown below:



The API responds with JSON. So we need to parse it into an object with response.json(), and then we can do whatever we want with the resulting object. In the above code, we simply write the object to the console. The following screenshot shows the results:


results from writing the object to the consoleresults from writing the object to the consoleresults from writing the object to the console

As you can see, the Nutrition Analysis API provides a wealth of nutritional information about the ingredient.


Conclusion


If you are building food and nutrition-based applications and you need an accurate source of nutritional information, then you need the APILayer Food APIs. No matter which API or subscription plan you choose, your users can benefit from its natural language processing and accurate health, diet, and allergy information. It's easy to use and easy to get started. So head over to the APILayer Marketplace and create an account today!



Original Link: https://code.tutsplus.com/tutorials/analyze-recipes-and-nutrition-with-apilayer-food-apis--cms-41545

Share this article:    Share on Facebook
View Full Article

TutsPlus - Code

Tuts+ is a site aimed at web developers and designers offering tutorials and articles on technologies, skills and techniques to improve how you design and build websites.

More About this Source Visit TutsPlus - Code