简体   繁体   English

在 Javascript 中,我如何从 edamam 营养 API 中提取膳食类型

[英]In Javascript how do I pull mealtype from edamam nutritional API

I am trying to pull the mealtype from the following API.我正在尝试从以下 API 中提取膳食类型。

https://developer.edamam.com/edamam-docs-nutrition-api https://developer.edamam.com/edamam-docs-nutrition-api

Reading the API understand that we need to use a POST request to get a response specifically for mealType data.阅读 API 了解到我们需要使用 POST 请求来获取专门针对 mealType 数据的响应。 However I am very confused on how the syntax would be written for this.但是,我对如何为此编写语法感到非常困惑。

for example the user puts in lasagna and the api gives me the meal type which should be Italian.例如,用户放入烤宽面条,api 给了我应该是意大利语的膳食类型。

Step 1, write a service that sends a post request when you run your script.第 1 步,编写一个在运行脚本时发送 post 请求的服务。 I'm assuming here you're using node, so we'd have something like, let say APIGetter.我在这里假设您正在使用节点,所以我们会有类似的东西,比如说 APIGetter。 In the api getter, you want to send out an http request.在 api getter 中,您想发送一个 http 请求。

I suggest using the request module .我建议使用request 模块 Now when you call this function, it'll return a json string inside a promise, containing a bunch of information.现在当你调用这个函数时,它会在一个 promise 中返回一个 json 字符串,其中包含一堆信息。 You can then deserialize it (turn it into a javascript object) using JSON.parse.然后你可以使用 JSON.parse 反序列化它(把它变成一个 javascript 对象)。

However, I don't think the API does what you think it does, it gives nutrition information given a list of ingredients.但是,我认为 API 并没有像您想象的那样做,它根据成分列表提供营养信息。 It will not categorize the food for you.它不会为您分类食物。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM