Answers for "axios get request with body"

6

Using axios send a GET request to the address:

// Send a POST request
axios({
  method: 'post',
  url: '/user/12345',
  data: {
    firstName: 'Fred',
    lastName: 'Flintstone'
  }
});
Posted by: Guest on April-10-2020
6

axios api post request

import qs from 'qs';
const data = { 'bar': 123 };
const options = {
  method: 'POST',
  headers: { 'content-type': 'application/x-www-form-urlencoded' },
  data: qs.stringify(data),
  url,
};
axios(options);
Posted by: Guest on August-08-2020
2

how to make request with axios

const axios = require('axios');

async function makeGetRequest() {

  let res = await axios.get('http://webcode.me');

  let data = res.data;
  console.log(data);
}

makeGetRequest();
Posted by: Guest on August-10-2020
0

Using axios send a GET request to the address:

// Make a request for a user with a given ID
axios.get('/user?ID=12345')
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

// Optionally the request above could also be done as
axios.get('/user', {
    params: {
      ID: 12345
    }
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
Posted by: Guest on April-10-2020
0

axios get request with body

/**
 * Package that needed:
 * 'qs', 'axios' 
 * install by `npm install qs --save 
 */

// You can Add more to this 
let headers = {
	'content-type': 'application/x-www-form-urlencoded',
};

let body = {
    field1: 'foo',
    field2: 'bar',
};

// For async_await
let reponse = await axios({
	method: 'POST',
    headers: headers,
    data: qs.stringify(body), // <---- This step it is important
    url: `${YOUR_URL}`,
}); 


return response['data'];
Posted by: Guest on September-29-2021

Code answers related to "axios get request with body"

Code answers related to "Javascript"

Browse Popular Code Answers by Language