Fitness freaks 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 using Spoonacular API.
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.
Demo Time:
Reference:
https://spoonacular.com/food-api
Other Posts
Object Identification using Google Cloud Vision in Salesforce
Logo Recognition using Google Cloud Vision in Salesforce
Extract Text From Images using Google Cloud Vision
Google FitBit Integration with Salesforce
Audio to Text by Google Speech API in Salesforce Lightning