Skip to content

Instantly share code, notes, and snippets.

@jochasinga
Last active March 7, 2019 05:48
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 jochasinga/b1bd19242b28eac1e277ef4701a47eb3 to your computer and use it in GitHub Desktop.
Save jochasinga/b1bd19242b28eac1e277ef4701a47eb3 to your computer and use it in GitHub Desktop.
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