import fetch from 'fetch'; /** * Describes the attributes on the fetch configuration object */ interface FetchConfig { url: string; headers?: { [key: string]: string }; } /** * Conveniently gets a JSON response using the fetch api * @param {FetchConfig} config * @return {Promise} */ const getJSON = (config: FetchConfig): Promise => { const fetchConfig = { method: 'GET', Accept: 'application/json', 'Content-Type': 'application/json', ...(config.headers || {}) }; return fetch(config.url, fetchConfig).then(response => response.json()); }; export { getJSON };