home
  • Blog
  • Home
  • Projects
    • Ember
    • EmberData
    • Ember CLI
2.18
  • Packages
    • ember-data
  • Classes
    • DS.AbortError
    • DS.Adapter
    • DS.AdapterError
    • DS.AdapterPopulatedRecordArray
    • DS.BelongsToReference
    • DS.BooleanTransform
    • DS.BuildURLMixin
    • DS.ConflictError
    • DS.DateTransform
    • DS.EmbeddedRecordsMixin
    • DS.Errors
    • DS.FilteredRecordArray
    • DS.ForbiddenError
    • DS.HasManyReference
    • DS.InvalidError
    • DS.JSONAPIAdapter
    • DS.JSONAPISerializer
    • DS.JSONSerializer
    • DS.ManyArray
    • DS.Model
    • DS.NotFoundError
    • DS.NumberTransform
    • DS.PromiseArray
    • DS.PromiseManyArray
    • DS.PromiseObject
    • DS.RESTAdapter
    • DS.RESTSerializer
    • DS.RecordArray
    • DS.RecordReference
    • DS.RootState
    • DS.Serializer
    • DS.ServerError
    • DS.Store
    • DS.StringTransform
    • DS.TimeoutError
    • DS.Transform
    • DS.UnauthorizedError
    • Ember.Inflector

Class DS.BuildURLMixin


Defined in: addon/-private/adapters/build-url-mixin.js:6
Module: ember-data

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.


Methods

buildURL (modelName, id, snapshot, requestType, query) : String

Module: ember-data

Defined in addon/-private/adapters/build-url-mixin.js:34

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

Module: ember-data

Defined in addon/-private/adapters/build-url-mixin.js:411

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
import DS from 'ember-data';
import { decamelize } from '@ember/string';
import { pluralize } from 'ember-inflector';

export default DS.RESTAdapter.extend({
  pathForType: function(modelName) {
    var decamelized = decamelize(modelName);
    return pluralize(decamelized);
  }
});

urlForCreateRecord (modelName, snapshot) : String

Module: ember-data

Defined in addon/-private/adapters/build-url-mixin.js:299

modelName
String
snapshot
DS.Snapshot
returns
String

url

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

urlForDeleteRecord (id, modelName, snapshot) : String

Module: ember-data

Defined in addon/-private/adapters/build-url-mixin.js:349

id
String
modelName
String
snapshot
DS.Snapshot
returns
String

url

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

urlForFindAll (modelName, snapshot) : String

Module: ember-data

Defined in addon/-private/adapters/build-url-mixin.js:138

modelName
String
snapshot
DS.SnapshotRecordArray
returns
String

url

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

urlForFindBelongsTo (id, modelName, snapshot) : String

Module: ember-data

Defined in addon/-private/adapters/build-url-mixin.js:272

id
String
modelName
String
snapshot
DS.Snapshot
returns
String

url

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

urlForFindHasMany (id, modelName, snapshot) : String

Module: ember-data

Defined in addon/-private/adapters/build-url-mixin.js:245

id
String
modelName
String
snapshot
DS.Snapshot
returns
String

url

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

urlForFindMany (ids, modelName, snapshots) : String

Module: ember-data

Defined in addon/-private/adapters/build-url-mixin.js:217

ids
Array
modelName
String
snapshots
Array
returns
String

url

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

urlForFindRecord (id, modelName, snapshot) : String

Module: ember-data

Defined in addon/-private/adapters/build-url-mixin.js:111

id
String
modelName
String
snapshot
DS.Snapshot
returns
String

url

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(modelName, id, snapshot);
    return `${baseUrl}/users/${snapshot.adapterOptions.user_id}/playlists/${id}`;
  }
});

urlForQuery (query, modelName) : String

Module: ember-data

Defined in addon/-private/adapters/build-url-mixin.js:162

query
Object
modelName
String
returns
String

url

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

urlForQueryRecord (query, modelName) : String

Module: ember-data

Defined in addon/-private/adapters/build-url-mixin.js:192

query
Object
modelName
String
returns
String

url

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

urlForUpdateRecord (id, modelName, snapshot) : String

Module: ember-data

Defined in addon/-private/adapters/build-url-mixin.js:324

id
String
modelName
String
snapshot
DS.Snapshot
returns
String

url

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}`;
  }
});
On this page


Methods

  • buildURL
  • pathForType
  • urlForCreateRecord
  • urlForDeleteRecord
  • urlForFindAll
  • urlForFindBelongsTo
  • urlForFindHasMany
  • urlForFindMany
  • urlForFindRecord
  • urlForQuery
  • urlForQueryRecord
  • urlForUpdateRecord
Team Sponsors Security Legal Branding Community Guidelines
Twitter GitHub Discord Mastodon

If you want help you can contact us by email, open an issue, or get realtime help by joining the Ember Discord.

© Copyright 2025 - Tilde Inc.
Ember.js is free, open source and always will be.


Ember is generously supported by
blue Created with Sketch.