Thursday, 18 April 2019

Http Client in Node.js

Making HTTP(S) calls from the application is very common requirement. Node.JS world offers lots of options about how to implement it, or better to say - which package to use.

Native solution

Node.JS comes with native http and https packages.

Request package

It does not support Promises so if we need to wrap it into a Promise ourselves...something like:

 * Function which fetches http response asynchronously.
 * It is implemented as a simple Promise wrapper around request API.
 * @param url Request URL.
function fetchData(url: string): Promise<string> {
    return new Promise((resolve, reject) => {
        if (!url) {

        request(url, (error: any, response: request.Response, body: any) => {
            if (error) {
            } else {
                if (response) {
                    console.log("statusCode: ", response.statusCode);
                    if (body) {
                    } else {
                } else {

Request package with native promises

node-fetch package

window.fetch API for Node.js 

Axios package

Promise based HTTP client for the browser and node.js

Some References


I've been looking solutions which support Promises. node-fetch seems to be traditional approach and Axios seems to be very popular among developers now.


micheal pan said...

BE SMART AND BECOME RICH IN LESS THAN 3DAYS....It all depends on how fast 
you can be to get the new PROGRAMMED blank ATM card that is capable of
hacking into any ATM machine,anywhere in the world. I got to know about 
this BLANK ATM CARD when I was searching for job online about a month 
ago..It has really changed my life for good and now I can say I'm rich and 
I can never be poor again. The least money I get in a day with it is about 
$50,000.(fifty thousand USD) Every now and then I keeping pumping money 
into my account. Though is illegal,there is no risk of being caught 
,because it has been programmed in such a way that it is not traceable,it 
also has a technique that makes it impossible for the CCTVs to detect 
you..For details on how to get yours today, email the hackers on : ( ). Tell your 
loved once too, and start to live large. That's the simple testimony of how 
my life changed for good...Love you all ...the email address again is ;

DANIEL RAY said...


I was scammed of $573,000 worth of bitcoins with a scam forest investment unknowingly then, I didn’t know what to do.. I felt like committing suicide, but I fortunately for me I had a good start again after my friend introduced me to a cyber crime investigator ( Mr Morris Gray ) who helped me recovered all my stolen funds and profit that where held form me, by those bastard scammers, in just few days of working with him, if you feel scammed with fake forex company you don’t need to be worried, you can Text Him Via his Email: Morris Gray 830@ gmail . com or WhatsApp +1 (607) 698-0239. And he will recover your stolen coins back in your wallet account in full...he has all it takes and his a very straight forward person!!!
I recommend him too anyone out there, who has fall a victim of crypto scam before.