Last active
April 1, 2019 18:24
-
-
Save raduGaspar/b566b819adaa46dfb7c746ec974912c0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const API = (function () { | |
const url = 'https://purelyawespme.com/api' | |
const handleError = (res) => res.ok ? res : Promise.reject(res.statusText) | |
const doGet = (endpoint) => window.fetch(url + endpoint, { | |
method: 'GET', | |
headers: new Headers({ | |
'Accept': 'application/json' | |
}) | |
}) | |
.then(handleError) | |
.catch(error => { throw new Error(error) }) | |
const doPost = (endpoint, body) => window.fetch(url + endpoint, { | |
method: 'POST', | |
headers: { 'Content-Type': 'application/json' }, | |
body | |
}) | |
.then(handleError) | |
.catch(error => { throw new Error(error) }) | |
return { | |
post: doPost, | |
get: doGet | |
} | |
}()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment