Fitness fricks always talk about carbs, protein and fats. They eat fruit, vegetable based on these parameters. This blog will show carbs, protein, fats and calories for given fruit or vegetable.
There are lot of food APIs to get nutrition and recipe for food products. Below are some Food APIs
I have used Spoonacular API to get food nutrition. Below are steps to get free API access
- Register at https://spoonacular.com/food-api/pricing
- Select Free plan to check API
- Get API key at https://spoonacular.com/food-api/console#Profile
Now we have API key to use in Apex class to get product nutrition. Let us create Lightning Web Component for this. Below two steps are required
- Create Apex class to call API
- Create Lightning Web Component to show product information
Create Apex class to call API:
We need to call Spoonacular API using GET method of HTTPRequest. API key need to be added in GET request of API request. Change apiKey based on your profile.
callout.endPointurl='https://api.spoonacular.com/recipes/guessNutrition?'+ 'apiKey=*******************'+ '&title='+foodName;
Create Lightning Web Component
Create lightning web component which will show product information. I have added one combo box with some predefined options, if you want to get information about other fruit or product, select other in option and enter fruit name in text box.