Skip to content

Instantly share code, notes, and snippets.

@funador
Last active January 21, 2019 15:34
Show Gist options
  • Save funador/3f07d410095e5f425e0bd117aafe2011 to your computer and use it in GitHub Desktop.
Save funador/3f07d410095e5f425e0bd117aafe2011 to your computer and use it in GitHub Desktop.
const api = (() => {
const url = `${window.location.origin}/api`
const addTodo = todo =>
axios.post(url, todo)
.then(res => res.data)
const deleteTodo = id =>
axios.delete(`${url}/${id}`)
.then(res => res.data)
const updateTodo = (update, id) =>
axios.put(`${url}/${id}`, update)
.then(res => res.data)
const getTodos = () =>
axios.get(url)
.then(res => res.data)
return {
addTodo,
deleteTodo,
updateTodo,
getTodos
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment