Created
November 24, 2017 19:46
-
-
Save nomanHasan/a6e8c207191254ac24f8d6948f205d52 to your computer and use it in GitHub Desktop.
TodoApi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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