3 Promise-based Http Clients to use in NodeJS
Hi Coders,
Today I am going to discuss promise based http clients that I am using in my current Node.js project at DLT Labs.
Promise-based clients are better than callback
An http client is useful whenever a request needs to be sent to another server. As we all know, callback is an old concept. So we need an http client which is promise-based.
Here are 3 of the most reliable http clients which can be used in Node.js :
- Axios
- Request-promise
- Superagent
Let’s understand the format and dependencies of each of the above packages.
1) Axios
Along with node.js, Axios supports almost all the latest versions of browsers i.e. Firefox, Chrome, IE, Edge, Safari for sending requests.
For installing using npm :
npm install axios
Using then/catch:
let axios = require(“axios”);
axios({
method: “POST”,
url: “https://abc.com/api/auth/change/password” ,
data:{
“oldpassword”: “test124”,
“newpassword”: “test12@”
}).then(response=>{
console.log(response)…