#

API Docs for: v3.16.0-alpha.2
Show: Inherited Protected Private Deprecated

# BuildURLMixin Class

Defined in: `../adapter/addon/-private/build-url-mixin.js:10`
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 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.

- Index
- Methods

## Item Index

### Methods

- _buildURL
- buildURL
- pathForType
- urlForCreateRecord
- urlForDeleteRecord
- urlForFindAll
- urlForFindBelongsTo
- urlForFindHasMany
- urlForFindMany
- urlForFindRecord
- urlForQuery
- urlForQueryRecord
- urlForUpdateRecord
- urlPrefix

## Methods

### `_buildURL`

(

- `modelName`
- `id`

)
String private

Defined in `../adapter/addon/-private/build-url-mixin.js:84`

#### Parameters:

- `modelName` String
- `id` String

#### Returns:

String:

url

### `buildURL`

(

- `modelName`
- `id`
- `snapshot`
- `requestType`
- `query`

)
String

Defined in `../adapter/addon/-private/build-url-mixin.js:36`

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.

#### Parameters:

- `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

### `pathForType`

(

- `modelName`

)
String

Defined in `../adapter/addon/-private/build-url-mixin.js:423`

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

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

#### Parameters:

- `modelName` String

#### Returns:

String:

path

### `urlForCreateRecord`

(

- `modelName`
- `snapshot`

)
String

Defined in `../adapter/addon/-private/build-url-mixin.js:307`

Builds a URL for a `record.save()` call when the record was created locally using `store.createRecord()`.

Example:

    import RESTAdapter from '@ember-data/adapter/rest';

    export default RESTAdapter.extend({
      urlForCreateRecord(modelName, snapshot) {
        return this._super(...arguments) + '/new';
      }
    });

#### Parameters:

- `modelName` String
- `snapshot` Snapshot

#### Returns:

String:

url

### `urlForDeleteRecord`

(

- `id`
- `modelName`
- `snapshot`

)
String

Defined in `../adapter/addon/-private/build-url-mixin.js:357`

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

Example:

    import RESTAdapter from '@ember-data/adapter/rest';

    export default RESTAdapter.extend({
      urlForDeleteRecord(id, modelName, snapshot) {
        return this._super(...arguments) + '/destroy';
      }
    });

#### Parameters:

- `id` String
- `modelName` String
- `snapshot` Snapshot

#### Returns:

String:

url

### `urlForFindAll`

(

- `modelName`
- `snapshot`

)
String

Defined in `../adapter/addon/-private/build-url-mixin.js:146`

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

Example:

    import JSONAPIAdapter from '@ember-data/adapter/json-api';

    export default JSONAPIAdapter.extend({
      urlForFindAll(modelName, snapshot) {
        return 'data/comments.json';
      }
    });

#### Parameters:

- `modelName` String
- `snapshot` SnapshotRecordArray

#### Returns:

String:

url

### `urlForFindBelongsTo`

(

- `id`
- `modelName`
- `snapshot`

)
String

Defined in `../adapter/addon/-private/build-url-mixin.js:280`

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

Example:

    import JSONAPIAdapter from '@ember-data/adapter/json-api';

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

#### Parameters:

- `id` String
- `modelName` String
- `snapshot` Snapshot

#### Returns:

String:

url

### `urlForFindHasMany`

(

- `id`
- `modelName`
- `snapshot`

)
String

Defined in `../adapter/addon/-private/build-url-mixin.js:253`

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

Example:

    import JSONAPIAdapter from '@ember-data/adapter/json-api';

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

#### Parameters:

- `id` String
- `modelName` String
- `snapshot` Snapshot

#### Returns:

String:

url

### `urlForFindMany`

(

- `ids`
- `modelName`
- `snapshots`

)
String

Defined in `../adapter/addon/-private/build-url-mixin.js:225`

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

Example:

    import RESTAdapter from '@ember-data/adapter/rest';

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

#### Parameters:

- `ids` Array
- `modelName` String
- `snapshots` Array

#### Returns:

String:

url

### `urlForFindRecord`

(

- `id`
- `modelName`
- `snapshot`

)
String

Defined in `../adapter/addon/-private/build-url-mixin.js:119`

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

Example:

    import JSONAPIAdapter from '@ember-data/adapter/json-api';

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

#### Parameters:

- `id` String
- `modelName` String
- `snapshot` Snapshot

#### Returns:

String:

url

### `urlForQuery`

(

- `query`
- `modelName`

)
String

Defined in `../adapter/addon/-private/build-url-mixin.js:170`

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

Example:

    import RESTAdapter from '@ember-data/adapter/rest';

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

#### Parameters:

- `query` Object
- `modelName` String

#### Returns:

String:

url

### `urlForQueryRecord`

(

- `query`
- `modelName`

)
String

Defined in `../adapter/addon/-private/build-url-mixin.js:200`

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

Example:

    import RESTAdapter from '@ember-data/adapter/rest';

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

#### Parameters:

- `query` Object
- `modelName` String

#### Returns:

String:

url

### `urlForUpdateRecord`

(

- `id`
- `modelName`
- `snapshot`

)
String

Defined in `../adapter/addon/-private/build-url-mixin.js:332`

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

Example:

    import RESTAdapter from '@ember-data/adapter/rest';

    export default RESTAdapter.extend({
      urlForUpdateRecord(id, modelName, snapshot) {
        return /${id}/feed?access_token=${snapshot.adapterOptions.token};
      }
    });

#### Parameters:

- `id` String
- `modelName` String
- `snapshot` Snapshot

#### Returns:

String:

url

### `urlPrefix`

(

- `path`
- `parentURL`

)
String private

Defined in `../adapter/addon/-private/build-url-mixin.js:382`

#### Parameters:

- `path` String
- `parentURL` String

#### Returns:

String:

urlPrefix