How to use the isomorphic-fetch/fetch-npm-node.js function in isomorphic-fetch

To help you get started, we’ve selected a few isomorphic-fetch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ustwo / ustwo.com-frontend / src / app / lib / fetcher.js View on Github external
function fetcher (config) {
  const mergedConfig = Object.assign({}, defaultConfig, config);
  const url = mergedConfig.api() + mergedConfig.url;
  log('Fetching:', url);
  const req = fetch(url, mergedConfig)
    .then(response => {
      remove(mergedConfig.url);
      if (response.status >= 400) {
        if(mergedConfig.failure) {
          mergedConfig.failure(response);
        } else {
          throw new Error('Bad response from server');
        }
      }
      return response.json().then(data => {
        return {
          postsPaginationTotal: response.headers.get('X-WP-TotalPages'),
          eventsPaginationTotal: response.headers.get('X-WP-TotalPages'),
          archivedEventsPaginationTotal: response.headers.get('X-WP-TotalPages'),
          data: data
        }