Created
July 2, 2019 13:47
-
-
Save daniilgri/c67d7507e544236032ec77467b4af488 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ChatService { | |
_baseApi = `http://localhost:5000/api`; | |
async getResourse(url, type = null) { | |
const res = await fetch(this._baseApi + url, type); | |
const resJSON = await res.json(); | |
if (!res.ok) { | |
throw new Error(resJSON.message); | |
} | |
return resJSON; | |
} | |
async login(values) { | |
await this.getResourse(`/auth/login`, { | |
method: "POST", | |
mode: "cors", | |
cache: "no-cache", | |
credentials: "same-origin", | |
headers: { | |
"Content-Type": "application/json" | |
}, | |
referrer: "no-referrer", | |
body: JSON.stringify(values) | |
}); | |
} | |
} | |
export default ChatService; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment