intro to axios code example

Example 1: axios post

axios.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

Example 2: how to use axios get

const req = async () => {
  const response = await axios.get('https://dog.ceo/api/breeds/list/all')
  console.log(response)
}
req() // Calling this will make a get request and log the response.

Example 3: what is axios used for

Axios is a Promise-based HTTP client for JavaScript which can be used in your 
front-end application and in your Node. js backend. By using Axios it's easy 
to send asynchronous HTTP request to REST endpoints and perform CRUD 
operations.

Tags:

Php Example