Created
August 16, 2020 23:19
-
-
Save IgorHalfeld/0d83c6abb89974a5e7d546305551c6db to your computer and use it in GitHub Desktop.
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
const METHODS = ['get', 'post']; | |
export const createHTTPClient = baseURL => METHODS.reduce((acc, cur) => ({ | |
...acc, | |
[cur]: async (path, options) => { | |
const res = await window.fetch(`${baseURL}${path}`, { method: cur.toLowerCase(), ...options }); | |
const json = await res.json(); | |
return json; | |
}, | |
}), {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment