Defined in: addon/-private/adapters/build-url-mixin.js:5
Module: ember-data
WARNING: This interface is likely to change in order to accomodate https://github.com/emberjs/rfcs/pull/4
To use url building, include the mixin when extending an adapter, and call buildURL
where needed. The default behaviour is designed for RESTAdapter.
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'); } });
The host
and namespace
attributes will be used if defined, and are optional.
String
private
String
String
String
String
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.
String
(String|Array|Object)
(DS.Snapshot|Array)
String
Object
String
String
Determines the pathname for a given type.
By default, it pluralizes the type's name (for example, 'post' becomes 'posts' and 'person' becomes 'people').
For example if you have an object LineItem with an endpoint of "/line_items/".
app/adapters/application.js
import DS from 'ember-data'; export default DS.RESTAdapter.extend({ pathForType: function(modelName) { var decamelized = Ember.String.decamelize(modelName); return Ember.String.pluralize(decamelized); } });
String
String
String
Builds a URL for a record.save()
call when the record was created locally using store.createRecord()
.
Example:
app/adapters/application.js
import DS from 'ember-data'; export default DS.RESTAdapter.extend({ urlForCreateRecord(modelName, snapshot) { return this._super(...arguments) + '/new'; } });
String
DS.Snapshot
String
String
Builds a URL for a record.save()
call when the record has been deleted locally.
Example:
app/adapters/application.js
import DS from 'ember-data'; export default DS.RESTAdapter.extend({ urlForDeleteRecord(id, modelName, snapshot) { return this._super(...arguments) + '/destroy'; } });
String
String
DS.Snapshot
String
String
Builds a URL for a store.findAll(type)
call.
Example:
app/adapters/comment.js
import DS from 'ember-data'; export default DS.JSONAPIAdapter.extend({ urlForFindAll(modelName, snapshot) { return 'data/comments.json'; } });
String
DS.SnapshotRecordArray
String
String
Builds a URL for fetching a async belongsTo relationship when a url is not provided by the server.
Example:
app/adapters/application.js
import DS from 'ember-data'; export default DS.JSONAPIAdapter.extend({ urlForFindBelongsTo(id, modelName, snapshot) { let baseUrl = this.buildURL(id, modelName); return `${baseUrl}/relationships`; } });
String
String
DS.Snapshot
String
String
Builds a URL for fetching a async hasMany relationship when a url is not provided by the server.
Example:
app/adapters/application.js
import DS from 'ember-data'; export default DS.JSONAPIAdapter.extend({ urlForFindHasMany(id, modelName, snapshot) { let baseUrl = this.buildURL(id, modelName); return `${baseUrl}/relationships`; } });
String
String
DS.Snapshot
String
String
Builds a URL for coalesceing multiple store.findRecord(type, id)
records into 1 request when the adapter's
coalesceFindRequests` property is true.
Example:
app/adapters/application.js
import DS from 'ember-data'; export default DS.RESTAdapter.extend({ urlForFindMany(ids, modelName) { let baseUrl = this.buildURL(); return `${baseUrl}/coalesce`; } });
Array
String
Array
String
String
Builds a URL for a store.findRecord(type, id)
call.
Example:
app/adapters/user.js
import DS from 'ember-data'; export default DS.JSONAPIAdapter.extend({ urlForFindRecord(id, modelName, snapshot) { let baseUrl = this.buildURL(); return `${baseUrl}/users/${snapshot.adapterOptions.user_id}/playlists/${id}`; } });
String
String
DS.Snapshot
String
String
Builds a URL for a store.query(type, query)
call.
Example:
app/adapters/application.js
import DS from 'ember-data'; export default DS.RESTAdapter.extend({ host: 'https://api.github.com', urlForQuery (query, modelName) { switch(modelName) { case 'repo': return `https://api.github.com/orgs/${query.orgId}/repos`; default: return this._super(...arguments); } } });
Object
String
String
String
Builds a URL for a store.queryRecord(type, query)
call.
Example:
app/adapters/application.js
import DS from 'ember-data'; export default DS.RESTAdapter.extend({ urlForQueryRecord({ slug }, modelName) { let baseUrl = this.buildURL(); return `${baseUrl}/${encodeURIComponent(slug)}`; } });
Object
String
String
String
Builds a URL for a record.save()
call when the record has been update locally.
Example:
app/adapters/application.js
import DS from 'ember-data'; export default DS.RESTAdapter.extend({ urlForUpdateRecord(id, modelName, snapshot) { return `/${id}/feed?access_token=${snapshot.adapterOptions.token}`; } });
String
String
DS.Snapshot
String
String
private
String
String
String
© 2017 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
http://emberjs.com/api/data/classes/DS.BuildURLMixin.html