Convert action to ts

- Add optional header support
- Add optional body support
This commit is contained in:
Joel Male
2020-08-26 09:36:04 +10:00
parent 749e2dcbc6
commit 00f958821e
18 changed files with 1836 additions and 46 deletions
+26
View File
@@ -0,0 +1,26 @@
class Http {
async make(url: string, headers: string, body: string): Promise<any> {
return new Promise((resolve, reject) => {
fetch(url, this.getOptions('post', headers, body))
.then((res) => resolve(res.body))
.catch((res) => reject(res.body));
});
}
getOptions(method: string, headers: string, body: string) {
const options: any = {
headers: JSON.parse(headers),
method
};
// stringify the body
options.body = JSON.stringify(body);
// set these headers
options.headers['content-type'] = 'application/json';
return options;
}
}
export const http = new Http();