How to use ember-fetch - 4 common examples

To help you get started, we’ve selected a few ember-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 ember-cli / ember-fetch / addon / utils / mung-options-for-fetch.ts View on Github external
if (hash.data) {
    // GET and HEAD requests can't have a `body`
    if (hash.method === 'GET' || hash.method === 'HEAD') {
      // If no options are passed, Ember Data sets `data` to an empty object, which we test for.
      if (Object.keys(hash.data).length) {
        // Test if there are already query params in the url (mimics jQuey.ajax).
        const queryParamDelimiter = hash.url.indexOf('?') > -1 ? '&' : '?';
        hash.url += `${queryParamDelimiter}${serializeQueryParams(hash.data)}`;
      }
    } else {
      // NOTE: a request's body cannot be a POJO, so we stringify it if it is.
      // JSON.stringify removes keys with values of `undefined` (mimics jQuery.ajax).
      // If the data is not a POJO (it's a String, FormData, etc), we just set it.
      // If the data is a string, we assume it's a stringified object.
      if (isPlainObject(hash.data)) {
        hash.body = JSON.stringify(hash.data);
      } else {
        hash.body = hash.data;
      }
    }
  }

  return hash;
}
github ember-cli / ember-fetch / tests / dummy / app / routes / index.js View on Github external
model: function() {
    return hash({
      fetch: fetch('/omg.json').then(function(request) {
        return request.json();
      }),
      ajax: ajax('/omg.json')
    });
  }
});
github ember-cli / ember-fetch / test / fixtures / dummy / app / routes / index.js View on Github external
model: function() {
    return hash({
      fetch: fetch('/omg.json').then(function(request) {
        return request.json();
      }),
      request: fetch(new Request('/omg.json')).then(function(request) {
        return request.json();
      }),
      ajax: ajax('/omg.json')
    });
  }
});
github travis-ci / travis-web / app / services / ajax.js View on Github external
setupUrl(requestUrl, method, options) {
    const { host = '', data } = options;
    const baseUrl = `${host}${requestUrl}`;

    if (data && this.isRetrieve(method)) {
      const params = serializeQueryParams(data);
      const delimeter = baseUrl.indexOf('?') === -1 ? '?' : '&';
      return `${baseUrl}${delimeter}${params}`;
    }

    return baseUrl;
  },

ember-fetch

HTML5 Fetch polyfill (as an ember-addon)

MIT
Latest version published 2 years ago

Package Health Score

51 / 100
Full package analysis