How can I make an HTTP request from within Node.js or Express.js? I need to connect to another service. I am hoping the call is asynchronous and that the callback contains the remote server's response.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- Keeping track of variable instances
Request and Superagent are pretty good libraries to use.
Using
request
:Check out httpreq: it's a node library I created because I was frustrated there was no simple http GET or POST module out there ;-)
Try using the simple
http.get(options, callback)
function in node.js:There is also a general
http.request(options, callback)
function which allows you to specify the request method and other request details.You can also use Requestify, a really cool and very simple HTTP client I wrote for nodeJS + it supports caching.
Just do the following for GET method request:
Check out shred. It's a node HTTP client created and maintained by spire.io that handles redirects, sessions, and JSON responses. It's great for interacting with rest APIs. See this blog post for more details.