How to use the @ember-data/adapter/rest.extend function in @ember-data/adapter

To help you get started, we’ve selected a few @ember-data/adapter 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 NREL / api-umbrella / src / api-umbrella / admin-ui / app / adapters / application.js View on Github external
import RESTAdapter from '@ember-data/adapter/rest';
import flatten from 'lodash-es/flatten';
import isArray from 'lodash-es/isArray';
import isPlainObject from 'lodash-es/isPlainObject';
import isString from 'lodash-es/isString';

export default RESTAdapter.extend({
  // Build the URL using the customizable "urlRoot" attribute that can be set
  // on the model class.
  buildURL(modelName, id, snapshot) {
    if(snapshot && snapshot.type && snapshot.type.urlRoot) {
      let url = snapshot.type.urlRoot;
      if(id) {
        url += '/' + encodeURIComponent(id);
      }

      return url;
    } else {
      return this._super(...arguments);
    }
  },

  // Ember data requires that errors from the API be returned as an array. This
github jelhan / croodle / app / adapters / application.js View on Github external
import RESTAdapter from '@ember-data/adapter/rest';
import { inject as service } from '@ember/service';
import AdapterFetch from 'ember-fetch/mixins/adapter-fetch';

export default RESTAdapter.extend(AdapterFetch, {
  encryption: service(),

  // set namespace to api.php in same subdirectory
  namespace:
    window.location.pathname
    // remove index.html if it's there
    .replace(/index.html$/, '')
    // remove tests prefix which is added by testem (starting with a number)
    .replace(/\/\d+\/tests/, '')
    // remove tests prefix which is added by tests run in browser
    .replace(/tests/, '')
    // remove leading and trailing slash
    .replace(/\/$/, '')
    // add api.php
    .concat('/api/index.php')
    // remove leading slash