Answers for "how to send object in axios post request"

15

axios send post data

// Send a POST request
axios({
  method: 'post',
  url: '/user/12345',
  data: {
    firstName: 'Fred',
    lastName: 'Flintstone'
  },
  headers: {'Authorization': 'Bearer ...'}
});
Posted by: Guest on April-13-2020
1

how to make a post request from axios

import axios from 'axios';

async makeRequest() {
  try {
    const response = await axios.post('your_request_url_here', {
    // Enter your body parameters here
    });
  }
  catch(e) {
    // Handle your error here
  }
}

// Axios returns a promise and hence you can use .then(), .catch for error
// handling if you don't want to use async/await(use try/catch for error 
// handling)
Posted by: Guest on March-07-2022
0

how to use post method axios

const handleClick = async () => {
    let fd = new FormData();
    fd.append("name", name);
    fd.append("password", password);
    const rep = await axios
      .post("http://localhost/php/api/students/create.php", fd)
      .catch((err) => {
        console.log(err, "axios error");
      });
    console.log(rep.data);
  };
Posted by: Guest on February-26-2022

Code answers related to "Javascript"

Browse Popular Code Answers by Language