Skip to content

Instantly share code, notes, and snippets.

@nomanHasan
Created November 24, 2017 19:46
Show Gist options
  • Save nomanHasan/a6e8c207191254ac24f8d6948f205d52 to your computer and use it in GitHub Desktop.
Save nomanHasan/a6e8c207191254ac24f8d6948f205d52 to your computer and use it in GitHub Desktop.
TodoApi
import {HttpClient} from './httpClient'
// This is the API. The backend root URL can be set from here.
const API = 'http://localhost:3000/api'
//Setting the todos URI
const TODO_API = `${API}/todos`
// The CRUD Operations of the Todo Resource.
//Create
const createTodo = todo => {
return HttpClient.post(TODO_API, todo)
}
//Read
const getTodo = () => {
return HttpClient.get(TODO_API)
}
//Update
const updateTodo = todo => {
return HttpClient.put(TODO_API, todo)
}
//Delete
const removeTodo = todo => {
return HttpClient.delete(`${TODO_API}/${todo._id}`)
}
//Encapsulating in a JSON object
const TodoApi = {createTodo, getTodo, updateTodo, removeTodo}
export {TodoApi}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment