diff --git a/src/utils/http-utils.ts b/src/utils/http-utils.ts new file mode 100644 index 0000000..7495f67 --- /dev/null +++ b/src/utils/http-utils.ts @@ -0,0 +1,35 @@ +import Constants from '@/constants'; + +export class HttpUtils +{ + private token: string = ''; + + public HttpUtils(token: string) + { + this.token = token; + } + + public post(node: string, body: any): Promise + { + // Add token + if (this.token != '') body['token'] = this.token; + + // Create promise + return new Promise((resolve, reject) => + { + // Fetch request + fetch(`${Constants.API_URL}${node}`, {method: 'POST', body: body}).then(res => + { + // Get response body text + res.text().then(text => + { + // Parse response + let response = JSON.parse(text); + resolve(response); + }) + .catch(reject) + }) + .catch(reject) + }); + } +}