Skip to content

Instantly share code, notes, and snippets.

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

Embed
What would you like to do?
Step one in refactor
async function postLoginData(data) {
const loginUrl = `${apiBaseUrl}/login`;
let response = await fetch(loginUrl, {
method: "POST",
mode: "cors",
cache: "no-cache",
credentials: "same-origin",
headers: {
"Content-Type": "application/json; charset=utf-8",
},
redirect: "follow",
referrer: "no-referrer",
body: JSON.stringify(data),
});
return response;
}
// Get the user's data based on user id.
async function getUser(userId) {
const userUrl = `${apiBaseUrl}/users/${userId}`;
let response = await fetch(userUrl, {
method: "GET",
mode: "cors",
cache: "no-cache",
credentials: "same-origin",
headers: {
"Content-Type": "application/json; charset=utf-8",
},
redirect: "follow",
referrer: "no-referrer",
});
return response;
}
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.