Last active
March 7, 2019 05:48
-
-
Save jochasinga/b1bd19242b28eac1e277ef4701a47eb3 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
const baseConfig = { | |
mode: "cors", | |
cache: "no-cache", | |
credentials: "same-origin", | |
headers: { | |
"Content-Type": "application/json; charset=utf-8", | |
}, | |
redirect: "follow", | |
referrer: "no-referrer", | |
}; | |
// Configurable POST with predefined config | |
async function post(uri, data, config = {}) { | |
config = Object.assign({ | |
method: "POST", | |
body: JSON.stringify(data), | |
...baseConfig, | |
}, config); | |
return await fetch(uri, config) | |
} | |
// Configurable GET with predefined config | |
async function get(uri, config = {}) { | |
config = Object.assign({ | |
method: "GET", | |
...baseConfig, | |
}, config); | |
return await fetch(uri, config); | |
} | |
export {get, post}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment