add API utils

This commit is contained in:
davidwells 2018-06-13 14:24:47 -07:00
parent 6eda508f0c
commit c348a515de

42
src/utils/api.js Normal file
View file

@ -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
}