Class DS.BuildURLMixin

WARNING: This interface is likely to change in order to accomodate https://github.com/emberjs/rfcs/pull/4

Using BuildURLMixin

To use url building, include the mixin when extending an adapter, and call buildURL where needed. The default behaviour is designed for RESTAdapter.

Example

1
2
3
4
5
6
  export default DS.Adapter.extend(BuildURLMixin, {
    findRecord: function(store, type, id, snapshot) {
      var url = this.buildURL(type.modelName, id, snapshot, 'findRecord');
      return this.ajax(url, 'GET');
    }
  });

Attributes

The host and namespace attributes will be used if defined, and are optional.

Show:

Module: ember-data
modelName
String
id
(String|Array|Object)
single id or array of ids or query
snapshot
(DS.Snapshot|Array)
single snapshot or array of snapshots
requestType
String
query
Object
object of query parameters to send for query requests.
returns
String
url

Builds a URL for a given type and optional ID.

By default, it pluralizes the type's name (for example, 'post' becomes 'posts' and 'person' becomes 'people'). To override the pluralization see pathForType.

If an ID is specified, it adds the ID to the path generated for the type, separated by a /.

When called by RESTAdapter.findMany() the id and snapshot parameters will be arrays of ids and snapshots.

Module: ember-data
modelName
String
returns
String
path

Determines the pathname for a given type.

By default, it pluralizes the type's name (for example, 'post' becomes 'posts' and 'person' becomes 'people').

Pathname customization

For example if you have an object LineItem with an endpoint of "/line_items/".

app/adapters/application.js
1
2
3
4
5
6
7
8
import DS from 'ember-data';

export default DS.RESTAdapter.extend({
  pathForType: function(modelName) {
    var decamelized = Ember.String.decamelize(modelName);
    return Ember.String.pluralize(decamelized);
  }
});
Module: ember-data
modelName
String
snapshot
DS.Snapshot
returns
String
url
Module: ember-data
id
String
modelName
String
snapshot
DS.Snapshot
returns
String
url
Module: ember-data
id
String
modelName
String
snapshot
DS.Snapshot
returns
String
url
Module: ember-data
modelName
String
returns
String
url
Module: ember-data
id
String
modelName
String
returns
String
url
Module: ember-data
id
String
modelName
String
returns
String
url
Module: ember-data
ids
Array
modelName
String
snapshots
Array
returns
String
url
Module: ember-data
query
Object
modelName
String
returns
String
url
Module: ember-data
query
Object
modelName
String
returns
String
url
Module: ember-data
id
String
modelName
String
snapshot
DS.Snapshot
returns
String
url