Last active
December 31, 2019 03:02
-
-
Save davidgilbertson/539eddf9e3e12dcbd8f9ee442f0b2d24 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
const fetchJson = (url, opts = {}) => fetch(url, { | |
method: opts.method, | |
headers: {'Content-Type': 'application/json'}, | |
body: opts.body && JSON.stringify(opts.body), | |
}).then(res => res.json()); | |
export default { | |
create: body => fetchJson(API_URL, { | |
method: 'POST', | |
body, | |
}), | |
read: id => fetchJson(`${API_URL}/${id}`), | |
update: (id, body) => fetchJson(`${API_URL}/${id}`, { | |
method: 'PUT', | |
body, | |
}), | |
delete: id => fetchJson(`${API_URL}/${id}`, { | |
method: 'DELETE', | |
}), | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment