Consuming external APIs from Node.js
There will undoubtedly be a time when you want to consume an API directly from within your Node.js code. Perhaps your own API endpoint needs to first fetch data from some other unrelated third-party API before sending a response. Whatever the reason, the act of sending a request to an external API endpoint and receiving a response can be done fairly easily using a popular and well-known npm module called request
. The request
module was written by Mikeal Rogers and is currently the third most popular (and most relied upon) npm module after async
and underscore
.
Request is basically a super simple HTTP client, so everything you've been doing with Postman REST Client so far is basically what Request
can do, only ...
Get Web Development with MongoDB and NodeJS - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.