Bhavya Ardeshana
Bhavya Ardeshana

Reputation: 65

How to convert request-promise get Request to Axios get Request

This is my request-promise get Request Code I want to convert this code to Axios get Request

let file = rp.get({
  uri: "url",
  headers: {
    "Accept": "message/rfc2822"
  }
}).auth("api", "ap`enter code here`i-key")
/**Access the buffer here**/
file.on('data', (data => {
  console.log("data", data)
  // Here I get blob format data
}))

Upvotes: 0

Views: 278

Answers (1)

NIKUNJ KOTHIYA
NIKUNJ KOTHIYA

Reputation: 2165

Axios code of your code will be:

axios.get("url", {
        headers: {
            Accept: "message/rfc2822"
        },
        auth: {
            username: "api",
            password: "api-key"
        },
        responseType: "stream"
    })
    .then(response => {
        response.data.pipe(concat(data => {
            console.log("data", data);
        }));
    })
    .catch(error => {
        console.error(error);
    });

Upvotes: 1

Related Questions