[+] Encapsulate method for http get

This commit is contained in:
Hykilpikonna
2020-08-01 15:48:58 -04:00
parent 1c63f795f4
commit 0c5b993f20
+21
View File
@@ -28,4 +28,25 @@ export class HttpUtils
.catch(reject)
});
}
public get(url: string): Promise<any>
{
// Create promise
return new Promise<any>((resolve, reject) =>
{
// Fetch request
fetch(url, {method: 'GET'}).then(res =>
{
// Get response body text
res.text().then(text =>
{
// Parse response
let response = JSON.parse(text);
resolve(response);
})
.catch(reject)
})
.catch(reject)
});
}
}