How to use the ember-fetch/types.isPlainObject function in ember-fetch

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;
}

ember-fetch

HTML5 Fetch polyfill (as an ember-addon)

MIT
Latest version published 2 years ago

Package Health Score

53 / 100
Full package analysis