home
  • Blog
  • Home
  • Projects
    • Ember
    • EmberData
    • Ember CLI
3.28
  • Packages
    • @ember-data/adapter
    • @ember-data/adapter/error
    • @ember-data/adapter/json-api
    • @ember-data/adapter/rest
    • @ember-data/canary-features
    • @ember-data/debug
    • @ember-data/deprecations
    • @ember-data/model
    • @ember-data/record-data
    • @ember-data/serializer
    • @ember-data/serializer/json
    • @ember-data/serializer/json-api
    • @ember-data/serializer/rest
    • @ember-data/store
  • Classes
    • AbortError
    • Adapter
    • AdapterError
    • AdapterPopulatedRecordArray
    • BelongsToReference
    • BooleanTransform
    • BuildURLMixin
    • ConflictError
    • DateTransform
    • EmbeddedRecordsMixin
    • Errors
    • ForbiddenError
    • HasManyReference
    • IdentifierCache
    • InvalidError
    • JSONAPIAdapter
    • JSONAPISerializer
    • JSONSerializer
    • ManyArray
    • MinimumAdapterInterface
    • MinimumSerializerInterface
    • Model
    • NotFoundError
    • NumberTransform
    • PromiseArray
    • PromiseManyArray
    • PromiseObject
    • RESTAdapter
    • RESTSerializer
    • RecordArray
    • RecordDataDefault
    • RecordDataStoreWrapper
    • RecordReference
    • Reference
    • Serializer
    • ServerError
    • Snapshot
    • SnapshotRecordArray
    • StableRecordIdentifier
    • Store
    • StringTransform
    • TimeoutError
    • Transform
    • UnauthorizedError

Class BuildURLMixin public


Defined in: ../adapter/addon/-private/build-url-mixin.ts:15
Module: @ember-data/adapter

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

import Adapter, { BuildURLMixin } from '@ember-data/adapter';

export default class ApplicationAdapter extends Adapter.extend(BuildURLMixin) {
  findRecord(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 public

Module: @ember-data/adapter

Defined in ../adapter/addon/-private/build-url-mixin.ts:42

modelName
String
id
(String|Array|Object)

single id or array of ids or query

snapshot
(Snapshot|SnapshotRecordArray)

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 public

Module: @ember-data/adapter

Defined in ../adapter/addon/-private/build-url-mixin.ts:447

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

export default class ApplicationAdapter extends RESTAdapter {
  pathForType(modelName) {
    var decamelized = decamelize(modelName);
    return pluralize(decamelized);
  }
}

urlForCreateRecord (modelName, snapshot) : String public

Module: @ember-data/adapter

Defined in ../adapter/addon/-private/build-url-mixin.ts:328

modelName
String
snapshot
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 RESTAdapter from '@ember-data/adapter/rest';

export default class ApplicationAdapter extends RESTAdapter {
  urlForCreateRecord(modelName, snapshot) {
    return super.urlForCreateRecord(...arguments) + '/new';
  }
}

urlForDeleteRecord (id, modelName, snapshot) : String public

Module: @ember-data/adapter

Defined in ../adapter/addon/-private/build-url-mixin.ts:380

id
String
modelName
String
snapshot
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 RESTAdapter from '@ember-data/adapter/rest';

export default class ApplicationAdapter extends RESTAdapter {
  urlForDeleteRecord(id, modelName, snapshot) {
    return super.urlForDeleteRecord(...arguments) + '/destroy';
  }
}

urlForFindAll (modelName, snapshot) : String public

Module: @ember-data/adapter

Defined in ../adapter/addon/-private/build-url-mixin.ts:160

modelName
String
snapshot
SnapshotRecordArray
returns
String

url

Builds a URL for a store.findAll(type) call.

Example:

app/adapters/comment.js
import JSONAPIAdapter from '@ember-data/adapter/json-api';

export default class ApplicationAdapter extends JSONAPIAdapter {
  urlForFindAll(modelName, snapshot) {
    let baseUrl = this.buildURL(modelName);
    return `${baseUrl}/data/comments.json`;
  }
}

urlForFindBelongsTo (id, modelName, snapshot) : String public

Module: @ember-data/adapter

Defined in ../adapter/addon/-private/build-url-mixin.ts:300

id
String
modelName
String
snapshot
Snapshot
returns
String

url

Builds a URL for fetching an async belongsTo relationship when a url is not provided by the server.

Example:

app/adapters/application.js
import JSONAPIAdapter from '@ember-data/adapter/json-api';

export default class ApplicationAdapter extends JSONAPIAdapter {
  urlForFindBelongsTo(id, modelName, snapshot) {
    let baseUrl = this.buildURL(modelName, id);
    return `${baseUrl}/relationships`;
  }
}

urlForFindHasMany (id, modelName, snapshot) : String public

Module: @ember-data/adapter

Defined in ../adapter/addon/-private/build-url-mixin.ts:272

id
String
modelName
String
snapshot
Snapshot
returns
String

url

Builds a URL for fetching an async hasMany relationship when a URL is not provided by the server.

Example:

app/adapters/application.js
import JSONAPIAdapter from '@ember-data/adapter/json-api';

export default class ApplicationAdapter extends JSONAPIAdapter {
  urlForFindHasMany(id, modelName, snapshot) {
    let baseUrl = this.buildURL(modelName, id);
    return `${baseUrl}/relationships`;
  }
}

urlForFindMany (ids, modelName, snapshots) : String public

Module: @ember-data/adapter

Defined in ../adapter/addon/-private/build-url-mixin.ts:243

ids
Array
modelName
String
snapshots
Array
returns
String

url

Builds a URL for coalescing multiple store.findRecord(type, id) records into 1 request when the adapter's coalesceFindRequests property is true.

Example:

app/adapters/application.js
import RESTAdapter from '@ember-data/adapter/rest';

export default class ApplicationAdapter extends RESTAdapter {
  urlForFindMany(ids, modelName) {
    let baseUrl = this.buildURL();
    return `${baseUrl}/coalesce`;
  }
}

urlForFindRecord (id, modelName, snapshot) : String public

Module: @ember-data/adapter

Defined in ../adapter/addon/-private/build-url-mixin.ts:132

id
String
modelName
String
snapshot
Snapshot
returns
String

url

Builds a URL for a store.findRecord(type, id) call.

Example:

app/adapters/user.js
import JSONAPIAdapter from '@ember-data/adapter/json-api';

export default class ApplicationAdapter extends JSONAPIAdapter {
  urlForFindRecord(id, modelName, snapshot) {
    let baseUrl = this.buildURL(modelName, id, snapshot);
    return `${baseUrl}/users/${snapshot.adapterOptions.user_id}/playlists/${id}`;
  }
}

urlForQuery (query, modelName) : String public

Module: @ember-data/adapter

Defined in ../adapter/addon/-private/build-url-mixin.ts:186

query
Object
modelName
String
returns
String

url

Builds a URL for a store.query(type, query) call.

Example:

app/adapters/application.js
import RESTAdapter from '@ember-data/adapter/rest';

export default class ApplicationAdapter extends RESTAdapter {
  host = 'https://api.github.com';
  urlForQuery (query, modelName) {
    switch(modelName) {
      case 'repo':
        return `https://api.github.com/orgs/${query.orgId}/repos`;
      default:
        return super.urlForQuery(...arguments);
    }
  }
}

urlForQueryRecord (query, modelName) : String public

Module: @ember-data/adapter

Defined in ../adapter/addon/-private/build-url-mixin.ts:217

query
Object
modelName
String
returns
String

url

Builds a URL for a store.queryRecord(type, query) call.

Example:

app/adapters/application.js
import RESTAdapter from '@ember-data/adapter/rest';

export default class ApplicationAdapter extends RESTAdapter {
  urlForQueryRecord({ slug }, modelName) {
    let baseUrl = this.buildURL();
    return `${baseUrl}/${encodeURIComponent(slug)}`;
  }
}

urlForUpdateRecord (id, modelName, snapshot) : String public

Module: @ember-data/adapter

Defined in ../adapter/addon/-private/build-url-mixin.ts:354

id
String
modelName
String
snapshot
Snapshot
returns
String

url

Builds a URL for a record.save() call when the record has been updated locally.

Example:

app/adapters/application.js
import RESTAdapter from '@ember-data/adapter/rest';

export default class ApplicationAdapter extends RESTAdapter {
  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.