Created
January 5, 2021 01:12
-
-
Save s-barrah/05e9094dca4856d18ead8f369c482cd4 to your computer and use it in GitHub Desktop.
This file contains 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 fetch from 'node-fetch'; | |
const BASE_URL = process.env.BASE_URL; | |
const post = (data = {}, url = '') => { | |
return new Promise((resolve, reject) => { | |
return fetch(BASE_URL + url, { | |
method: 'post', | |
body: JSON.stringify(data), | |
headers: { 'Content-Type': 'application/json' }, | |
}) | |
.then((res) => res.json()) | |
.then((json) => { | |
resolve(json); | |
}) | |
.catch((error) => { | |
reject(error); | |
}) | |
}) | |
} | |
export default { | |
createList: (data) => post(data, 'list/create'), | |
getList: (data) => post(data, 'list'), | |
updateList: (data) => post(data, 'list/update'), | |
deleteList: (data) => post(data, 'list/delete'), | |
createTask: (data) => post(data, 'task/create'), | |
getTask: (data) => post(data, 'task'), | |
updateTask: (data) => post(data, 'task/update'), | |
deleteTask: (data) => post(data, 'task/delete'), | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment