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
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.
buildURL (modelName, id, snapshot, requestType, query) String
Defined in packages/ember-data/lib/adapters/build-url-mixin.js:31
- 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.
pathForType (modelName) String
Defined in packages/ember-data/lib/adapters/build-url-mixin.js:293
- 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/".
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
pathForType: function(modelName) {
var decamelized = Ember.String.decamelize(modelName);
return Ember.String.pluralize(decamelized);
}
});
urlForCreateRecord (modelName, snapshot) String
Defined in packages/ember-data/lib/adapters/build-url-mixin.js:218
- modelName
- String
- snapshot
- DS.Snapshot
- returns
- String
url
urlForDeleteRecord (id, modelName, snapshot) String
Defined in packages/ember-data/lib/adapters/build-url-mixin.js:239
- id
- String
- modelName
- String
- snapshot
- DS.Snapshot
- returns
- String
url
urlForFind (id, modelName, snapshot) String
Defined in packages/ember-data/lib/adapters/build-url-mixin.js:124
- id
- String
- modelName
- String
- snapshot
- DS.Snapshot
- returns
- String
url
urlForFindAll (modelName) String
Defined in packages/ember-data/lib/adapters/build-url-mixin.js:142
- modelName
- String
- returns
- String
url
urlForFindBelongTo (id, modelName) String
Defined in packages/ember-data/lib/adapters/build-url-mixin.js:208
- id
- String
- modelName
- String
- returns
- String
url
urlForFindHasMany (id, modelName) String
Defined in packages/ember-data/lib/adapters/build-url-mixin.js:198
- id
- String
- modelName
- String
- returns
- String
url
urlForFindMany (ids, modelName, snapshots) String
Defined in packages/ember-data/lib/adapters/build-url-mixin.js:187
- ids
- Array
- modelName
- String
- snapshots
- Array
- returns
- String
url
urlForQuery (query, modelName) String
Defined in packages/ember-data/lib/adapters/build-url-mixin.js:160
- query
- Object
- modelName
- String
- returns
- String
url
urlForQueryRecord (query, modelName) String
Defined in packages/ember-data/lib/adapters/build-url-mixin.js:177
- query
- Object
- modelName
- String
- returns
- String
url
urlForUpdateRecord (id, modelName, snapshot) String
Defined in packages/ember-data/lib/adapters/build-url-mixin.js:228
- id
- String
- modelName
- String
- snapshot
- DS.Snapshot
- returns
- String
url