如何向 3rd 方 API 编写 Node.js 请求?
有没有人有一个 API 响应从第 3 方发出的 http.request()
传回我的 clientSever 并写出到客户端浏览器的示例?
我一直陷入我确信简单的逻辑之中。我通过阅读文档使用express,它似乎没有为此提供抽象。
谢谢
Does anyone have an example of an API response being passed back from a http.request()
made to a 3rd party back to my clientSever and written out to a clients browser?
I keep getting stuck in what I'm sure is simple logic. I'm using express from reading the docs it doesn't seem to supply an abstraction for this.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请注意,这里的答案有点过时了——您会收到一条已弃用的警告。 2013 年的等效内容可能是:
如果您要编写大量此类内容,我还会推荐 request 模块。从长远来看,它会为您节省大量击键次数!
Note that the answer here is a little out of date-- You'll get a deprecated warning. The 2013 equivalent might be:
I would also recommend the request module if you're going to be writing a lot of these. It'll save you a lot of keystrokes in the long run!
以下是在快速获取函数中访问外部 API 的快速示例:
希望有帮助!
Here is a quick example of accessing an external API in an express get function:
Hope that helps!
此示例看起来与您想要实现的目标非常相似(纯 Node.js,无 Express):
http://blog.tredix.com/2011/03/partly-cloudy-nodejs-and-ifs.html
HTH
This example looks pretty similar to what you are trying to achieve (pure Node.js, no express):
http://blog.tredix.com/2011/03/partly-cloudy-nodejs-and-ifs.html
HTH