Skip to content

Instantly share code, notes, and snippets.

@daniilgri
Created July 2, 2019 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daniilgri/c67d7507e544236032ec77467b4af488 to your computer and use it in GitHub Desktop.
Save daniilgri/c67d7507e544236032ec77467b4af488 to your computer and use it in GitHub Desktop.
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