showing results for - "post request with body and headers 2c async await"
Bobby
17 Apr 2016
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
28
29
similar questions