Skip to content

Instantly share code, notes, and snippets.

@jochasinga jochasinga/refactor2.js
Last active Mar 7, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.