2020-08-26 00:10:43 +00:00
|
|
|
const axios = require('axios').default;
|
2020-08-26 00:00:45 +00:00
|
|
|
|
2020-08-25 23:36:04 +00:00
|
|
|
class Http {
|
|
|
|
async make(url: string, headers: string, body: string): Promise<any> {
|
|
|
|
return new Promise((resolve, reject) => {
|
2020-08-26 00:10:43 +00:00
|
|
|
axios({
|
|
|
|
method: 'post',
|
|
|
|
url,
|
|
|
|
headers: this.getHeaders(headers),
|
|
|
|
data: JSON.parse(body)
|
|
|
|
})
|
2020-08-25 23:36:04 +00:00
|
|
|
.then((res) => resolve(res.body))
|
|
|
|
.catch((res) => reject(res.body));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-26 00:10:43 +00:00
|
|
|
getHeaders(headersString: string): object {
|
|
|
|
const headers = JSON.parse(headersString);
|
2020-08-25 23:36:04 +00:00
|
|
|
|
|
|
|
// set these headers
|
2020-08-26 00:10:43 +00:00
|
|
|
headers['content-type'] = 'application/json';
|
2020-08-25 23:36:04 +00:00
|
|
|
|
2020-08-26 00:10:43 +00:00
|
|
|
return headers;
|
2020-08-25 23:36:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const http = new Http();
|