class UserService { constructor(config) { this.baseUrl = config.API_BASE_URL; this.urlTail = "user"; } async getUser(username, password) { const response = await fetch(`${this.baseUrl}${this.urlTail}`, { method: "GET", headers: { "X-Username": username, "X-Password": password, }, }); let body = null; try { body = await response.json(); } catch { console.error("Error in getUser"); } return { status: response.status, ok: response.ok, body: body, }; } async deleteUser(username, password) { const response = await fetch(`${this.baseUrl}${this.urlTail}`, { method: "DELETE", headers: { "X-Username": username, "X-Password": password, }, }); let body = null; try { body = await response.json(); } catch { console.error("Error in deleteUser"); } return { status: response.status, ok: response.ok, body: body, }; } async postUser(username) { const response = await fetch(`${this.baseUrl}${this.urlTail}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ username: username, }), }); let body = null; try { body = await response.json(); } catch { console.error("Error in postUser"); } return { status: response.status, ok: response.ok, body: body, }; } } window.UserService = UserService;