add API utils
This commit is contained in:
parent
6eda508f0c
commit
c348a515de
1 changed files with 42 additions and 0 deletions
42
src/utils/api.js
Normal file
42
src/utils/api.js
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue