Wondering how I can make a GET request to a JSON API using Node.js. I preferably want to use Express however it is not necessary, and for the output to be on a Jade page. I'm still completely new to Node.js and backend languages as a whole.
相关问题
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- google-drive can't get push notifications
- Google places autocomplete suggestion without coun
- How to reimport module with ES6 import
- Karate API Testing - Access variable value across
I like to use the request package:
And the code:
This will make an HTTP request to the API and upon success parse the response into JSON.
As far as getting the response onto a Jade page do you wish to do an API call (to your own server) and then use AngularJS/ jQuery/ another framework to fill in the information?
If you wish to add this to your own route consider embedding it like such:
Also, the same people who brought you the
request
package, have come out with a promise based version backed by bluebird called, not surprisingly,request-promise
:request-promise npm page
Some folks also prefer super agent, which allows you to chain commands:
superagent npm page
Here's an example from their docs: