axios timeout post example 1

axios timeout post example

//example of an axios post request with body and config object with timeout
//timeout is response (not request) timeout
axios.post('http://mysite.com/user', { name: 'John' }, { timeout: 2 })
  .then(response => {     console.log(response);  })
  .catch(error => {     console.log(error);  });

Here is what the above code is Doing:
1. We’re making a POST request to http://mysite.com/user with a body of { name: ‘John’ }.
2. We’re setting a timeout of 2 seconds.
3. If the request is successful, we log the response.
4. If the request fails, we log the error.

Similar Posts