With the help of Axios, the user can send GET, POST, PUT, and DELETE requests to the REST API and render a response to the application. With the help of Axios, users can interact with the REST API. In general, Axios is a promise-based HTTP client which used by the react-native.

Axios is associated with a number of features which are enlisted below:

  • It makes XMLHttpRequests from the browser
  • From react native framework, it makes Http requests
  • It supports react-native API’s
  • It provides a client-side feature that protects the application from XSRF.
  • It automatically transforms response and request data.

How to use Axios

  • You have to install Axios using npm
    npm install axios
  • After that you have to import this module.
    import axios from 'axios';
BY Best Interview Question ON 27 May 2021

Example

Using POST method.

axios.post('/login', {
       username: 'bestinterviewquestion',
       password: 'admin@123'
  })
  .then(function (response) {
        console.log(response);
  })
  .catch(function (error) {
       console.log(error);
  });