diff --git a/src/utils/api.js b/src/utils/api.js new file mode 100644 index 0000000..1078dd1 --- /dev/null +++ b/src/utils/api.js @@ -0,0 +1,42 @@ +/* Api methods to call /functions */ + +const create = (data) => { + console.log('run new create') + return fetch('/.netlify/functions/todos-create', { + body: JSON.stringify(data), + method: 'POST' + }).then(response => { + return response.json() + }) +} + +const readAll = () => { + return fetch('/.netlify/functions/todos-read-all').then((response) => { + console.log(response) + return response.json() + }) +} + +const update = (todoId, data) => { + return fetch(`/.netlify/functions/todos-update/${todoId}`, { + body: JSON.stringify(data), + method: 'POST' + }).then(response => { + return response.json() + }) +} + +const deleteTodo = (todoId) => { + return fetch(`/.netlify/functions/todos-delete/${todoId}`, { + method: 'POST', + }).then(response => { + return response.json() + }) +} + +export default { + create: create, + readAll: readAll, + update: update, + delete: deleteTodo +}