1import qs from 'qs';
2const data = { 'bar': 123 };
3const options = {
4 method: 'POST',
5 headers: { 'content-type': 'application/x-www-form-urlencoded' },
6 data: qs.stringify(data),
7 url,
8};
9axios(options);
1// Make a request for a user with a given ID
2axios.get('/user?ID=12345')
3 .then(function (response) {
4 console.log(response);
5 })
6 .catch(function (error) {
7 console.log(error);
8 });
9
10// Optionally the request above could also be done as
11axios.get('/user', {
12 params: {
13 ID: 12345
14 }
15 })
16 .then(function (response) {
17 console.log(response);
18 })
19 .catch(function (error) {
20 console.log(error);
21 });
1// GET request for remote image
2axios({
3 method: 'get',
4 url: 'http://bit.ly/2mTM3nY',
5 responseType: 'stream'
6})
7 .then(function(response) {
8 response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
9});
1/**
2 * Package that needed:
3 * 'qs', 'axios'
4 * install by `npm install qs --save
5 */
6
7// You can Add more to this
8let headers = {
9 'content-type': 'application/x-www-form-urlencoded',
10};
11
12let body = {
13 field1: 'foo',
14 field2: 'bar',
15};
16
17// For async_await
18let reponse = await axios({
19 method: 'POST',
20 headers: headers,
21 data: qs.stringify(body), // <---- This step it is important
22 url: `${YOUR_URL}`,
23});
24
25
26return response['data'];
27