webhook-action/src/http.ts

27 lines
633 B
TypeScript
Raw Normal View History

2020-08-26 00:10:43 +00:00
const axios = require('axios').default;
2020-08-26 00:00:45 +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)
})
.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);
// set these headers
2020-08-26 00:10:43 +00:00
headers['content-type'] = 'application/json';
2020-08-26 00:10:43 +00:00
return headers;
}
}
export const http = new Http();