From c348a515de9227de1dd507dc0540c6c0dbf8e78e Mon Sep 17 00:00:00 2001 From: davidwells Date: Wed, 13 Jun 2018 14:24:47 -0700 Subject: [PATCH] add API utils --- src/utils/api.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/utils/api.js 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 +}