Skip to content

Instantly share code, notes, and snippets.

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