2020-08-26 00:20:01 +00:00
|
|
|
const fetch = require('node-fetch');
|
2020-08-26 00:00:45 +00:00
|
|
|
|
2020-08-25 23:36:04 +00:00
|
|
|
class Http {
|
2020-08-26 00:31:06 +00:00
|
|
|
make(url: string, headers: string, body: string): Promise<any> {
|
2020-08-26 00:20:01 +00:00
|
|
|
return new Promise(() => {
|
|
|
|
fetch(url, this.getOptions('post', headers, body));
|
2020-08-25 23:36:04 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-26 00:20:01 +00:00
|
|
|
getOptions(method: string, headers: string, body: string) {
|
|
|
|
const options: any = {
|
|
|
|
headers: JSON.parse(headers),
|
|
|
|
method
|
|
|
|
};
|
|
|
|
|
|
|
|
// stringify the body
|
|
|
|
options.body = JSON.stringify(body);
|
2020-08-25 23:36:04 +00:00
|
|
|
|
|
|
|
// set these headers
|
2020-08-26 00:20:01 +00:00
|
|
|
options.headers['content-type'] = 'application/json';
|
2020-08-25 23:36:04 +00:00
|
|
|
|
2020-08-26 00:20:01 +00:00
|
|
|
return options;
|
2020-08-25 23:36:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const http = new Http();
|