Skip to content

Instantly share code, notes, and snippets.

@IgorHalfeld
Created August 16, 2020 23:19
Show Gist options
  • Save IgorHalfeld/0d83c6abb89974a5e7d546305551c6db to your computer and use it in GitHub Desktop.
Save IgorHalfeld/0d83c6abb89974a5e7d546305551c6db to your computer and use it in GitHub Desktop.
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