/** * HTTP request utility methods. * * @export * @abstract * @class Http */ export abstract class Http { /** * Use fetch to get. * * @static * @param {string} url Url to get. * @return {Promise} */ public static async get(url: string): Promise { return fetch(url); } /** * Use fetch to post. * * @static * @param {string} url Url to post. * @param {object} body Post body. * @return {Promise} */ public static async post(url: string, body: object): Promise { return fetch(url, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(body), credentials: "include", }); } /** * Check if a status is Ok (2xx). * * @static * @param {number} status Status to check. * @return {boolean} If is 2xx. */ public static ok(status: number): boolean { return status >= 200 && status <= 299; } }