-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce6d4b7
commit e9ba9a1
Showing
9 changed files
with
488 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>Bookmark App</title><link rel="stylesheet" href="src/styles.css"/><link href="https://fonts.googleapis.com/css2?family=Lora:ital,wght@1,600&display=swap" rel="stylesheet"/></head><body><div class="container"><header><h1>Bookmark App</h1></header><div class="error-container"></div><main></main></div><script src="index_bundle.js"></script></body></html> |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,67 @@ | ||
const BASE_URL= "https://thinkful-list-api.herokuapp.com/juliabugayev"; | ||
|
||
let fetchBookMark = (...args) => { | ||
let error = null; | ||
return fetch(...args) | ||
.then ((response) => { | ||
if (!response.ok) { | ||
error = {code: response.status}; | ||
"use strict"; | ||
const BookmarkAPI = | ||
"https://thinkful-list-api.herokuapp.com/juliabugayev/bookmarks"; | ||
|
||
//...arg takes multiple arguments | ||
|
||
const apiFetch = function (...args) { | ||
let error; | ||
return fetch(...args) | ||
.then((Response) => { | ||
if (!Response.ok) { | ||
error = { code: Response.status }; | ||
|
||
if (!Response.headers.get("content-type").includes("json")) { | ||
error.message = Response.statusText; | ||
return Promise.reject(error); | ||
} | ||
return response.json(); | ||
} | ||
return Response.json(); | ||
}) | ||
.then((data) => { | ||
if (error){ | ||
error.message = data.message; | ||
return Promise.reject(error); | ||
} | ||
return data; | ||
}) | ||
if (error) { | ||
error.message = data.message; | ||
return Promise.reject(error); | ||
} | ||
return data; | ||
}); | ||
}; | ||
|
||
function deleteBookmark(id) { | ||
return apiFetch(`${BookmarkAPI}/${id}`, { | ||
method: "DELETE", | ||
}); | ||
} | ||
|
||
function updateBookmark(id, updateInfo) { | ||
const update = JSON.stringify(updateInfo); | ||
return apiFetch(`${BookmarkAPI}/${id}`, { | ||
method: "PATCH", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: update, | ||
}); | ||
} | ||
|
||
function addNewBookmark(bookmark) { | ||
const addBookmark = JSON.stringify(bookmark); | ||
return apiFetch(`${BookmarkAPI}`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: addBookmark, | ||
}); | ||
} | ||
|
||
function obtainBookmark() { | ||
return apiFetch(`${BookmarkAPI}`); | ||
} | ||
|
||
let bookMarkDelete =(id) => { | ||
return fetchBookMark(`${BASE_URL}/${id}}`,{ | ||
method: 'DELETE', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
|
||
}); | ||
}; | ||
|
||
let newBookMarkCreate = (bookmark) => { | ||
let newBookMark = JSON.stringify(bookmark); | ||
return fetchBookMark(BASE_URL , { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
}; | ||
|
||
let bookmarkGet = (bookmark) => { | ||
return fetchBookMark(BASE_URL, { | ||
method: 'GET', | ||
headers:{ | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
}; | ||
export default { | ||
deleteBookmark, | ||
obtainBookmark, | ||
addNewBookmark, | ||
updateBookmark, | ||
}; |
Oops, something went wrong.