Skip to content

Commit

Permalink
Add apiCalls
Browse files Browse the repository at this point in the history
  • Loading branch information
judy0ye committed Oct 15, 2023
1 parent 7e2625b commit 4d7f204
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/apiCalls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const getCookie = (name) => {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
};

export default async function fetchGameLink() {
const res = await fetch('http://localhost:3000/api/v0/games', {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': getCookie('X-CSRF-Token')
}
})
if (!res.ok) {
throw new Error( `${res.status}: Unable to retrieve link`)
}
const data = await res.json()
return data
}

0 comments on commit 4d7f204

Please sign in to comment.