Categories
React Answers

How to post request with JSON data with Axios?

Spread the love

To post request with JSON data with Axios, we call axios.post with the JSON payload as the 2nd argument.

For instance, we write

const dt = { data: { value: "abc" } };
const request = axios.post(url, dt);

to call axios.post with the request url and dt JSON request payload data.

Therefore, { data: { value: "abc" } } is the JSON request data for this POST request.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *