1.

How Axios works in React Native?

Answer»

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';
Example

Using POST method.

axios.post('/login', {
       username: 'bestinterviewquestion',
       PASSWORD: '[email protected]'
  })
  .then(function (response) {
        console.log(response);
  })
  .CATCH(function (error) {
       console.log(error);
  });



Discussion

No Comment Found