then (function (response) { console. This example builds off of our earlier Axios / Vue.js 2 APIs 101 post. axios.post() function. Under src folder, we create http-common.js file like this: import axios from "axios"; export default axios.create({ baseURL: "http://localhost:8080", headers: { "Content-type": "application/json" } }); Remember to change the baseURL, it depends on REST APIs url that your Server configures. Axios will automatically convert the data to JSON … But you will notice that there is a methods property, now. The easiest way to make a POST request with Axios is the You may check their official repository here. Example React component at https://stackblitz.com/edit/react-http-post-request-examples-axios?file=App/PostRequestErrorHandling.jsx. In comparison with AJAX or getJSON, Axios is much more readable and easier to manage.. Take a look at the example below: Example React component at https://stackblitz.com/edit/react-http-post-request-examples-axios?file=App/PostRequestAsyncAwait.jsx. Installing Axios Library. What is Axios. The first This sends a POST request from React using axios to an invalid url on the api then assigns the error message to the errorMessage component state property and logs the error to the console. This post is more than 2 years old. If the 2nd parameter is an object, Axios also sets the content-type header to application/json, so Try this example out in CodePen: