The Nutrition API extracts nutrition information from text using natural language processing. From food blogs to menus to recipes, it can read any text and calculate the corresponding nutrition data.
An intelligent feature of this API is custom portioning: if your text specifies quantities of individual food items or ingredients, the algorithm will automatically scale the nutrition data in the result accordingly.
HTTP GET
Returns a list of nutrition information extracted from given text. Nutrition data for each food item is scaled to 100g
unless a quantity is specified within the query
parameter.
query
(required) - query text to extract nutrition information.
X-Api-Key
(required) - API Key associated with your account.
Live Demo!
https://api.api-ninjas.com/v1/nutrition?query=
[
{
"name": "brisket",
"calories": 1312.3,
"serving_size_g": 453.592,
"fat_total_g": 82.9,
"fat_saturated_g": 33.2,
"protein_g": 132,
"sodium_mg": 217,
"potassium_mg": 781,
"cholesterol_mg": 487,
"carbohydrates_total_g": 0,
"fiber_g": 0,
"sugar_g": 0
},
{
"name": "fries",
"calories": 317.7,
"serving_size_g": 100,
"fat_total_g": 14.8,
"fat_saturated_g": 2.3,
"protein_g": 3.4,
"sodium_mg": 212,
"potassium_mg": 124,
"cholesterol_mg": 0,
"carbohydrates_total_g": 41.1,
"fiber_g": 3.8,
"sugar_g": 0.3
}
]
import requests
query = '1lb brisket and fries'
api_url = 'https://api.api-ninjas.com/v1/nutrition?query={}'.format(query)
response = requests.get(api_url, headers={'X-Api-Key': 'YOUR_API_KEY'})
if response.status_code == requests.codes.ok:
print(response.text)
else:
print("Error:", response.status_code, response.text)
var query = '1lb brisket and fries'
$.ajax({
method: 'GET',
url: 'https://api.api-ninjas.com/v1/nutrition?query=' + query,
headers: { 'X-Api-Key': 'YOUR_API_KEY'},
contentType: 'application/json',
success: function(result) {
console.log(result);
},
error: function ajaxError(jqXHR) {
console.error('Error: ', jqXHR.responseText);
}
});
const request = require('request');
var query = '1lb brisket and fries';
request.get({
url: 'https://api.api-ninjas.com/v1/nutrition?query=' + query,
headers: {
'X-Api-Key': 'YOUR_API_KEY'
},
}, function(error, response, body) {
if(error) return console.error('Request failed:', error);
else if(response.statusCode != 200) return console.error('Error:', response.statusCode, body.toString('utf8'));
else console.log(body)
});
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import com.fasterxml.jackson.databind.ObjectMapper;
URL url = new URL("https://api.api-ninjas.com/v1/nutrition?query=1lb brisket and fries");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("accept", "application/json");
InputStream responseStream = connection.getInputStream();
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(responseStream);
System.out.println(root.path("fact").asText());
let query = "1lb brisket and fries".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
let url = URL(string: "https://api.api-ninjas.com/v1/nutrition?query="+query!)!
var request = URLRequest(url: url)
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "X-Api-Key")
let task = URLSession.shared.dataTask(with: request) {(data, response, error) in
guard let data = data else { return }
print(String(data: data, encoding: .utf8)!)
}
task.resume()