I’m just getting started with Node, APIs, and web applications.
I understand the basic workings of Node.js and Express, but now I want to start making calls to other service’s APIs and to do stuff with their data.
Can you outline basic HTTP requests and how to grab/parse the responses in Node? I’m also interested in adding specific headers to my request (initially I’m using the http://www.getharvest.com API to crunch my timesheet data).
P.S. This seems simple, but a lot of searching didn’t turn up anything that answered my question. If this is dupe, let me know and I’ll delete.
You cannot fetch stuff with Express, you should use Mikeal’s request library for that specific purpose.
Installation:
npm install requestThe API for that library is very simple:
Edit: You’re better of using this library instead of the http default one because it has a much nicer API and some more advanced features (it even supports cookies).
UPDATE: request has been deprecated, but there are some nice alternatives still such as ‘got‘ or ‘superagent‘ (look them up on npm).