superagent vs axios code example

Example 1: superagent vs axios

npm install superagent --save

Example 2: superagent vs axios

const axios = require('axios');

(async () => {
  try {
    const response = await axios.get('https://the-one-api.dev/v2/book?api_key=MY_KEY')
    console.log(response.data.name);
  } catch (error) {
    console.log(error.response.body);
  }
})();

Example 3: superagent vs axios

npm install axios --save

Example 4: superagent vs axios

const superagent = require('superagent');

(async () => {
  try {
    const queryArguments = {
      api_key: 'MY_KEY'
    }

    const response = await superagent.get('https://the-one-api.dev/v2/book').query(queryArguments)
    console.log(response.body.name);
  } catch (error) {
    console.log(error.response.body);
  }
})();

Tags:

Misc Example