diff --git a/apiutils.js b/apiutils.js new file mode 100644 index 0000000..9bf7488 --- /dev/null +++ b/apiutils.js @@ -0,0 +1,29 @@ +const apiUrl = "http://localhost:4730/todos"; + +/* FUNCTION - to get todos from the API*/ + +export function fetchData(path = "", options = {}) { + return fetch(apiUrl + path, options).then((response) => response.json()); +} + +export function postData(newTodo) { + const options = { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(newTodo), + }; + return fetchData("", options); + //return fetch(apiUrl + path, options).then((response) => response.json()); +} +/* +export function deleteAllData(newTodo) { + Promise.all( + doneTodos.map((doneTodo) => + fetch(apiUrl + `/${doneTodo.id}`, { + method: "DELETE", + headers: { "Content-Type": "application/json" }, + }) + ) + ); +} + */ diff --git a/index.html b/index.html index 745d888..15d9f85 100644 --- a/index.html +++ b/index.html @@ -52,6 +52,6 @@