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 });
1const axios = require('axios');
2
3async function makeGetRequest() {
4
5 let res = await axios.get('http://webcode.me');
6
7 let data = res.data;
8 console.log(data);
9}
10
11makeGetRequest();
12
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