Class: HttpAdapter

HttpAdapter


new HttpAdapter(opts)

HttpAdapter class.

Method parameters:
Name Type Argument Description
opts Object <optional>

Configuration options.

Properties
Name Type Argument Default Description
basePath String <optional>
''

See HttpAdapter#basePath.

debug Boolean <optional>
false

See HttpAdapter#debug.

forceTrailingSlash Boolean <optional>
false

See HttpAdapter#forceTrailingSlash.

http Object <optional>
axios

See HttpAdapter#http.

httpConfig Object <optional>
{}

See HttpAdapter#httpConfig.

suffix String <optional>
''

See HttpAdapter#suffix.

useFetch Boolean <optional>
false

See HttpAdapter#useFetch.

Example
import { DataStore } from 'js-data';
import { HttpAdapter } from 'js-data-http';

const httpAdapter = new HttpAdapter();
const store = new DataStore();

store.registerAdapter('http', httpAdapter, { 'default': true });

store.defineMapper('school');
store.defineMapper('student');

// GET /school/1
store.find('school', 1).then((school) => {
  console.log('school');
});

Extends

This class extends the Adapter class.

Members


basePath

Set a base path in order to use absolute URLs instead of relative URLs.

Details
Type Since Source
String 3.0.0 src/index.js, line 71
Example
const httpAdapter = new HttpAdapter({
  basePath: 'https://mydomain.com'
});

debug

Whether to log debugging information.

Details
Type Default value Source
Boolean
false
node_modules/js-data-adapter/src/index.js, line 74
Inherited From:

forceTrailingSlash

Ensure that the request url has a trailing forward slash.

Details
Type Since Default value Source
Boolean 3.0.0
false
src/index.js, line 85

http

The HTTP function that actually makes the HTTP request. By default this is axios.


httpConfig

Default configuration options to be mixed into the config argument passed to HttpAdapter#http.

Details
Type Since Source
Object 3.0.0 src/index.js, line 108

raw

Whether to return a more detailed response object.

Details
Type Default value Source
Boolean
false
node_modules/js-data-adapter/src/index.js, line 83
Inherited From:

suffix

Add a suffix to the request url, e.g. ".json".

Details
Type Since Source
String 3.0.0 src/index.js, line 118

useFetch

Use window.fetch if available.

Details
Type Since Default value Source See
Boolean 3.0.0
false
src/index.js, line 127

Methods


<static> extend(props, classProps)

Create a subclass of this HttpAdapter:

Method parameters:
Name Type Argument Default Description
props Object <optional>
{}

Properties to add to the prototype of the subclass.

Properties
Name Type Argument Description
constructor Object <optional>

Provide a custom constructor function to be used as the subclass itself.

classProps Object <optional>
{}

Static properties to add to the subclass.

Return value:
Type Description
Constructor

Subclass of this HttpAdapter class.

Details
Since Source
3.0.0 src/index.js, line 1247
Example

// Normally you would do: import { HttpAdapter } from 'js-data-http';
// or: import { HttpAdapter } from 'js-data-http-node';
const JSDataHttp = require('js-data-http-node');
const { HttpAdapter } = JSDataHttp;
console.log('Using JSDataHttp v' + JSDataHttp.version.full);

// Extend the class using ES2015 class syntax.
class CustomHttpAdapterClass extends HttpAdapter {
  foo () { return 'bar'; }
  static beep () { return 'boop'; }
}
const customHttpAdapter = new CustomHttpAdapterClass();
console.log(customHttpAdapter.foo());
console.log(CustomHttpAdapterClass.beep());

// Extend the class using alternate method.
const OtherHttpAdapterClass = HttpAdapter.extend({
  foo () { return 'bar'; }
}, {
  beep () { return 'boop'; }
})
const otherHttpAdapter = new OtherHttpAdapterClass();
console.log(otherHttpAdapter.foo());
console.log(OtherHttpAdapterClass.beep());

// Extend the class, providing a custom constructor.
function AnotherHttpAdapterClass () {
  HttpAdapter.call(this);
  this.created_at = new Date().getTime();
}
HttpAdapter.extend({
  constructor: AnotherHttpAdapterClass,
  foo () { return 'bar'; }
}, {
  beep () { return 'boop'; }
})
const anotherHttpAdapter = new AnotherHttpAdapterClass();
console.log(anotherHttpAdapter.created_at);
console.log(anotherHttpAdapter.foo());
console.log(AnotherHttpAdapterClass.beep());

afterCount(mapper, props, opts, response)

Lifecycle method method called by count.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes count to wait for the Promise to resolve before continuing.

If opts.raw is true then response will be a detailed response object, otherwise response will be the count.

response may be modified. You can also re-assign response to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by count.

Method parameters:
Name Type Description
mapper Object

The mapper argument passed to count.

props Object

The props argument passed to count.

opts Object

The opts argument passed to count.

response Object | Response

Count or Response, depending on the value of opts.raw.

Properties:
Name Type Description
opts.op String

afterCount

Inherited From:

afterCreate(mapper, props, opts, response)

Lifecycle method method called by create.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes create to wait for the Promise to resolve before continuing.

If opts.raw is true then response will be a detailed response object, otherwise response will be the created record.

response may be modified. You can also re-assign response to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by create.

Method parameters:
Name Type Description
mapper Object

The mapper argument passed to create.

props Object

The props argument passed to create.

opts Object

The opts argument passed to create.

response Object | Response

Created record or Response, depending on the value of opts.raw.

Properties:
Name Type Description
opts.op String

afterCreate

Inherited From:

afterDEL(url, config, opts, response)

Method parameters:
Name Type Description
url String
config Object
opts Object
response Object
Details
Source
src/index.js, line 188

afterDestroy(mapper, id, opts, response)

Lifecycle method method called by destroy.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes destroy to wait for the Promise to resolve before continuing.

If opts.raw is true then response will be a detailed response object, otherwise response will be undefined.

response may be modified. You can also re-assign response to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by destroy.

Method parameters:
Name Type Description
mapper Object

The mapper argument passed to destroy.

id String | Number

The id argument passed to destroy.

opts Object

The opts argument passed to destroy.

response undefined | Response

undefined or Response, depending on the value of opts.raw.

Properties:
Name Type Description
opts.op String

afterDestroy

Inherited From:

afterDestroyAll(mapper, query, opts, response)

Lifecycle method method called by destroyAll.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes destroyAll to wait for the Promise to resolve before continuing.

If opts.raw is true then response will be a detailed response object, otherwise response will be undefined.

response may be modified. You can also re-assign response to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by destroyAll.

Method parameters:
Name Type Description
mapper Object

The mapper argument passed to destroyAll.

query Object

The query argument passed to destroyAll.

opts Object

The opts argument passed to destroyAll.

response undefined | Response

undefined or Response, depending on the value of opts.raw.

Properties:
Name Type Description
opts.op String

afterDestroyAll

Inherited From:

afterFind(mapper, id, opts, response)

Lifecycle method method called by find.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes find to wait for the Promise to resolve before continuing.

If opts.raw is true then response will be a detailed response object, otherwise response will be the found record, if any.

response may be modified. You can also re-assign response to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by find.

Method parameters:
Name Type Description
mapper Object

The mapper argument passed to find.

id String | Number

The id argument passed to find.

opts Object

The opts argument passed to find.

response Object | Response

The found record or Response, depending on the value of opts.raw.

Properties:
Name Type Description
opts.op String

afterFind

Inherited From:

afterFindAll(mapper, query, opts, response)

Lifecycle method method called by findAll.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes findAll to wait for the Promise to resolve before continuing.

If opts.raw is true then response will be a detailed response object, otherwise response will be the found records, if any.

response may be modified. You can also re-assign response to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by findAll.

Method parameters:
Name Type Description
mapper Object

The mapper argument passed to findAll.

query Object

The query argument passed to findAll.

opts Object

The opts argument passed to findAll.

response Array.<Object> | Response

The found records or Response, depending on the value of opts.raw.

Properties:
Name Type Description
opts.op String

afterFindAll

Inherited From:

afterGET(url, config, opts, response)

Method parameters:
Name Type Description
url String
config Object
opts Object
response Object
Details
Source
src/index.js, line 198

afterHTTP(config, opts, response)

Method parameters:
Name Type Description
config Object
opts Object
response Object
Details
Source
src/index.js, line 208

afterPOST(url, data, config, opts, response)

Method parameters:
Name Type Description
url String
data Object
config Object
opts Object
response Object
Details
Source
src/index.js, line 217

afterPUT(url, data, config, opts, response)

Method parameters:
Name Type Description
url String
data Object
config Object
opts Object
response Object
Details
Source
src/index.js, line 228

afterSum(mapper, field, query, opts, response)

Lifecycle method method called by sum.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes sum to wait for the Promise to resolve before continuing.

If opts.raw is true then response will be a detailed response object, otherwise response will be the sum.

response may be modified. You can also re-assign response to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by sum.

Method parameters:
Name Type Description
mapper Object

The mapper argument passed to sum.

field String

The field argument passed to sum.

query Object

The query argument passed to sum.

opts Object

The opts argument passed to sum.

response Object | Response

Count or Response, depending on the value of opts.raw.

Properties:
Name Type Description
opts.op String

afterSum

Inherited From:

afterUpdate(mapper, id, props, opts, response)

Lifecycle method method called by update.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes update to wait for the Promise to resolve before continuing.

If opts.raw is true then response will be a detailed response object, otherwise response will be the updated record.

response may be modified. You can also re-assign response to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by update.

Method parameters:
Name Type Description
mapper Object

The mapper argument passed to update.

id String | Number

The id argument passed to update.

props Object

The props argument passed to update.

opts Object

The opts argument passed to update.

response Object | Response

The updated record or Response, depending on the value of opts.raw.

Properties:
Name Type Description
opts.op String

afterUpdate

Inherited From:

afterUpdateAll(mapper, props, query, opts, response)

Lifecycle method method called by updateAll.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes updateAll to wait for the Promise to resolve before continuing.

If opts.raw is true then response will be a detailed response object, otherwise response will be the updated records, if any.

response may be modified. You can also re-assign response to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by updateAll.

Method parameters:
Name Type Description
mapper Object

The mapper argument passed to updateAll.

props Object

The props argument passed to updateAll.

query Object

The query argument passed to updateAll.

opts Object

The opts argument passed to updateAll.

response Array.<Object> | Response

The updated records or Response, depending on the value of opts.raw.

Properties:
Name Type Description
opts.op String

afterUpdateAll

Inherited From:

afterUpdateMany(mapper, records, opts, response)

Lifecycle method method called by updateMany.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes updateMany to wait for the Promise to resolve before continuing.

If opts.raw is true then response will be a detailed response object, otherwise response will be the updated records, if any.

response may be modified. You can also re-assign response to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by updateMany.

Method parameters:
Name Type Description
mapper Object

The mapper argument passed to updateMany.

records Array.<Object>

The records argument passed to updateMany.

opts Object

The opts argument passed to updateMany.

response Array.<Object> | Response

The updated records or Response, depending on the value of opts.raw.

Properties:
Name Type Description
opts.op String

afterUpdateMany

Inherited From:

beforeCount(mapper, query, opts)

Lifecycle method method called by count.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes count to wait for the Promise to resolve before continuing.

A thrown error or rejected Promise will bubble up and reject the Promise returned by count.

Method parameters:
Name Type Description
mapper Object

The mapper argument passed to count.

query Object

The query argument passed to count.

opts Object

The opts argument passed to count.

Properties:
Name Type Description
opts.op String

beforeCount

Inherited From:

beforeCreate(mapper, props, opts)

Lifecycle method method called by create.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes create to wait for the Promise to resolve before continuing.

props may be modified. You can also re-assign props to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by create.

Method parameters:
Name Type Description
mapper Object

The mapper argument passed to create.

props Object

The props argument passed to create.

opts Object

The opts argument passed to create.

Properties:
Name Type Description
opts.op String

beforeCreate

Inherited From:

beforeCreateMany(mapper, props, opts)

Lifecycle method method called by createMany.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes createMany to wait for the Promise to resolve before continuing.

props may be modified. You can also re-assign props to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by createMany.

Method parameters:
Name Type Description
mapper Object

The mapper argument passed to createMany.

props Array.<Object>

The props argument passed to createMany.

opts Object

The opts argument passed to createMany.

Properties:
Name Type Description
opts.op String

beforeCreateMany

Inherited From:

beforeDEL(url, config, opts)

Method parameters:
Name Type Description
url Object
config Object
opts Object
Details
Source
src/index.js, line 239

beforeDestroy(mapper, id, opts)

Lifecycle method method called by destroy.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes destroy to wait for the Promise to resolve before continuing.

A thrown error or rejected Promise will bubble up and reject the Promise returned by destroy.

Method parameters:
Name Type Description
mapper Object

The mapper argument passed to destroy.

id String | Number

The id argument passed to destroy.

opts Object

The opts argument passed to destroy.

Properties:
Name Type Description
opts.op String

beforeDestroy

Inherited From:

beforeDestroyAll(mapper, query, opts)

Lifecycle method method called by destroyAll.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes destroyAll to wait for the Promise to resolve before continuing.

A thrown error or rejected Promise will bubble up and reject the Promise returned by destroyAll.

Method parameters:
Name Type Description
mapper Object

The mapper argument passed to destroyAll.

query Object

The query argument passed to destroyAll.

opts Object

The opts argument passed to destroyAll.

Properties:
Name Type Description
opts.op String

beforeDestroyAll

Inherited From:

beforeFind(mapper, id, opts)

Lifecycle method method called by find.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes find to wait for the Promise to resolve before continuing.

A thrown error or rejected Promise will bubble up and reject the Promise returned by find.

Method parameters:
Name Type Description
mapper Object

The mapper argument passed to find.

id String | Number

The id argument passed to find.

opts Object

The opts argument passed to find.

Properties:
Name Type Description
opts.op String

beforeFind

Inherited From:

beforeFindAll(mapper, query, opts)

Lifecycle method method called by findAll.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes findAll to wait for the Promise to resolve before continuing.

A thrown error or rejected Promise will bubble up and reject the Promise returned by findAll.

Method parameters:
Name Type Description
mapper Object

The mapper argument passed to findAll.

query Object

The query argument passed to findAll.

opts Object

The opts argument passed to findAll.

Properties:
Name Type Description
opts.op String

beforeFindAll

Inherited From:

beforeGET(url, config, opts)

Method parameters:
Name Type Description
url Object
config Object
opts Object
Details
Source
src/index.js, line 248

beforeHTTP(config, opts)

Method parameters:
Name Type Description
config Object
opts Object
Details
Source
src/index.js, line 257

beforePOST(url, data, config, opts)

Method parameters:
Name Type Description
url Object
data Object
config Object
opts Object
Details
Source
src/index.js, line 265

beforePUT(url, data, config, opts)

Method parameters:
Name Type Description
url Object
data Object
config Object
opts Object
Details
Source
src/index.js, line 275

beforeSum(mapper, query, opts)

Lifecycle method method called by sum.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes sum to wait for the Promise to resolve before continuing.

A thrown error or rejected Promise will bubble up and reject the Promise returned by sum.

Method parameters:
Name Type Description
mapper Object

The mapper argument passed to sum.

query Object

The query argument passed to sum.

opts Object

The opts argument passed to sum.

Properties:
Name Type Description
opts.op String

beforeSum

Inherited From:

beforeUpdate(mapper, id, props, opts)

Lifecycle method method called by update.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes update to wait for the Promise to resolve before continuing.

props may be modified. You can also re-assign props to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by update.

Method parameters:
Name Type Description
mapper Object

The mapper argument passed to update.

id String | Number

The id argument passed to update.

props Object

The props argument passed to update.

opts Object

The opts argument passed to update.

Properties:
Name Type Description
opts.op String

beforeUpdate

Inherited From:

beforeUpdateAll(mapper, props, query, opts)

Lifecycle method method called by updateAll.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes updateAll to wait for the Promise to resolve before continuing.

props may be modified. You can also re-assign props to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by updateAll.

Method parameters:
Name Type Description
mapper Object

The mapper argument passed to updateAll.

props Object

The props argument passed to updateAll.

query Object

The query argument passed to updateAll.

opts Object

The opts argument passed to updateAll.

Properties:
Name Type Description
opts.op String

beforeUpdateAll

Inherited From:

beforeUpdateMany(mapper, props, opts)

Lifecycle method method called by updateMany.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes updateMany to wait for the Promise to resolve before continuing.

props may be modified. You can also re-assign props to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by updateMany.

Method parameters:
Name Type Description
mapper Object

The mapper argument passed to updateMany.

props Array.<Object>

The props argument passed to updateMany.

opts Object

The opts argument passed to updateMany.

Properties:
Name Type Description
opts.op String

beforeUpdateMany

Inherited From:

count(mapper, query, opts)

Retrieve the number of records that match the selection query.

Method parameters:
Name Type Argument Description
mapper Object

The mapper.

query Object

Selection query.

opts Object <optional>

Configuration options.

Properties
Name Type Argument Default Description
params String <optional>

Querystring parameters.

suffix String <optional>
HttpAdapter#suffix

See HttpAdapter#suffix.

Return value:
Type Description
Promise Unspecified
Details
Source Overrides
src/index.js, line 371 Adapter#count

create(mapper, props, opts)

Create a new the record from the provided props.

Method parameters:
Name Type Argument Description
mapper Object

The mapper.

props Object

Properties to send as the payload.

opts Object <optional>

Configuration options.

Properties
Name Type Argument Default Description
params String <optional>

Querystring parameters.

suffix String <optional>
HttpAdapter#suffix

See HttpAdapter#suffix.

Return value:
Type Description
Promise Unspecified
Details
Source Overrides
src/index.js, line 394 Adapter#create

createMany(mapper, props, opts)

Create multiple new records in batch.

Method parameters:
Name Type Argument Description
mapper Object

The mapper.

props Array

Array of property objects to send as the payload.

opts Object <optional>

Configuration options.

Properties
Name Type Argument Default Description
params String <optional>

Querystring parameters.

suffix String <optional>
HttpAdapter#suffix

See HttpAdapter#suffix.

Return value:
Type Description
Promise Unspecified
Details
Source Overrides
src/index.js, line 414 Adapter#createMany

dbg(args)

Log the provided values at the "debug" level. Debug-level logs are only logged if Component#debug is true.

.dbg(...) is shorthand for .log('debug', ...).

Method parameters:
Name Type Argument Description
args * <optional>
<repeatable>

Values to log.

Details
Since Source
3.0.0 node_modules/js-data/src/Component.js, line 124
Inherited From:

DEL(url, config, opts)

Make an Http request to url according to the configuration in config.

Method parameters:
Name Type Argument Description
url String

Url for the request.

config Object <optional>

Http configuration that will be passed to HttpAdapter#HTTP.

opts Object <optional>

Configuration options.

Return value:
Type Description
Promise Unspecified
Details
Source
src/index.js, line 434

deserialize(mapper, response, opts)

Transform the server response object into the payload that will be returned to JSData.

Method parameters:
Name Type Description
mapper Object

The mapper used for the operation.

response Object

Response object from HttpAdapter#HTTP.

opts Object

Configuration options.

Return value:
Type Description
Object | Array

Deserialized data.

Details
Source
src/index.js, line 470

destroy(mapper, id, opts)

Destroy the record with the given primary key.

Method parameters:
Name Type Argument Description
mapper Object

The mapper.

id String | Number

Primary key of the record to destroy.

opts Object <optional>

Configuration options.

Properties
Name Type Argument Default Description
params String <optional>

Querystring parameters.

suffix String <optional>
HttpAdapter#suffix

See HttpAdapter#suffix.

Return value:
Type Description
Promise Unspecified
Details
Source Overrides
src/index.js, line 495 Adapter#destroy

destroyAll(mapper, query, opts)

Destroy the records that match the selection query.

Method parameters:
Name Type Argument Description
mapper Object

The mapper.

query Object

Selection query.

opts Object <optional>

Configuration options.

Properties
Name Type Argument Default Description
params String <optional>

Querystring parameters.

suffix String <optional>
HttpAdapter#suffix

See HttpAdapter#suffix.

Return value:
Type Description
Promise Unspecified
Details
Source Overrides
src/index.js, line 515 Adapter#destroyAll

emit(event, args)

Trigger an event on this Component.

Method parameters:
Name Type Argument Description
event String

Name of event to emit.

args * <optional>
<repeatable>

Arguments to pass to any listeners.

Details
Since Source
3.0.0 node_modules/js-data/src/Component.js, line 202
Inherited From:
Example

// import {Collection, DataStore} from 'js-data'
const JSData = require('js-data@3.0.0-rc.4')
const {Collection, DataStore} = JSData

const collection = new Collection()
collection.on('foo', function (msg) {
  console.log(msg)
})
collection.emit('foo', 'bar')

const store = new DataStore()
store.on('beep', function (msg) {
  console.log(msg)
})
store.emit('beep', 'boop')

error(args)

Log an error.

Method parameters:
Name Type Argument Description
args * <optional>
<repeatable>

Arguments to log.

Details
Source
src/index.js, line 537

fetch(config)

Make an Http request using window.fetch.

Method parameters:
Name Type Description
config Object

Request configuration.

Properties
Name Type Description
data Object

Payload for the request.

method String

Http method for the request.

headers Object

Headers for the request.

params Object

Querystring for the request.

url String

Url for the request.

Details
Source
src/index.js, line 550

find(mapper, id, opts)

Retrieve the record with the given primary key.

Method parameters:
Name Type Argument Description
mapper Object

The mapper.

id String | Number

Primary key of the record to retrieve.

opts Object <optional>

Configuration options.

Properties
Name Type Argument Default Description
params String <optional>

Querystring parameters.

suffix String <optional>
HttpAdapter#suffix

See HttpAdapter#suffix.

Return value:
Type Description
Promise Unspecified
Details
Source Overrides
src/index.js, line 587 Adapter#find

findAll(mapper, query, opts)

Retrieve the records that match the selection query.

Method parameters:
Name Type Argument Description
mapper Object

The mapper.

query Object

Selection query.

opts Object <optional>

Configuration options.

Properties
Name Type Argument Default Description
params String <optional>

Querystring parameters.

suffix String <optional>
HttpAdapter#suffix

See HttpAdapter#suffix.

Return value:
Type Description
Promise Unspecified
Details
Source Overrides
src/index.js, line 607 Adapter#findAll

GET(url, config, opts)

Make a GET request.

Method parameters:
Name Type Argument Description
url String

The url for the request.

config Object

Request configuration options.

opts Object <optional>

Configuration options.

Return value:
Type Description
Promise Unspecified
Details
Source
src/index.js, line 629

getEndpoint(mapper, id, opts)

Method parameters:
Name Type Description
mapper Object

The Mapper.

id *

The primary key, if any.

opts Boolean

Configuration options.

Return value:
Type Description
String

Full path.

Details
Source
src/index.js, line 664

getOpt(opt, opts)

Resolve the value of the specified option based on the given options and this adapter's settings. Override with care.

Method parameters:
Name Type Argument Description
opt String

The name of the option.

opts Object <optional>

Configuration options.

Return value:
Type Description
*

The value of the specified option.

Inherited From:

getPath(method, mapper, id, opts)

Method parameters:
Name Type Argument Description
method String

The method being executed.

mapper Object

The Mapper.

id String | Number <nullable>

The primary key, if any.

opts Object

Configuration options.

Details
Source
src/index.js, line 719

HTTP(config, opts)

Make an Http request.

Method parameters:
Name Type Argument Description
config Object

Request configuration options.

opts Object <optional>

Configuration options.

Return value:
Type Description
Promise Unspecified
Details
Source
src/index.js, line 758

loadBelongsTo()

Load a belongsTo relationship.

Override with care.

Return value:
Type Description
Promise Unspecified
Inherited From:

loadHasMany()

Load a hasMany relationship.

Override with care.

Return value:
Type Description
Promise Unspecified
Inherited From:

loadHasOne()

Load a hasOne relationship.

Override with care.

Return value:
Type Description
Promise Unspecified
Inherited From:

log(level, args)

Log the provided values. By default sends values to console[level]. Debug-level logs are only logged if Component#debug is true.

Will attempt to use appropriate console methods if they are available.

Method parameters:
Name Type Argument Description
level String

Log level.

args * <optional>
<repeatable>

Values to log.

Details
Since Source
3.0.0 node_modules/js-data/src/Component.js, line 134
Inherited From:

makeBelongsToForeignKey()

Return the foreignKey from the given record for the provided relationship.

Override with care.

Return value:
Type Description
* Unspecified
Inherited From:

makeHasManyForeignKey()

Return the foreignKey from the given record for the provided relationship.

There may be reasons why you may want to override this method, like when the id of the parent doesn't exactly match up to the key on the child.

Override with care.

Return value:
Type Description
* Unspecified
Inherited From:

makeHasManyForeignKeys()

Return the foreignKeys from the given record for the provided relationship.

Override with care.

Return value:
Type Description
* Unspecified
Inherited From:

makeHasManyLocalKeys()

Return the localKeys from the given record for the provided relationship.

Override with care.

Return value:
Type Description
* Unspecified
Inherited From:

off(event, listener)

Remove an event listener from this Component. If no listener is provided, then all listeners for the specified event will be removed. If no event is specified then all listeners for all events will be removed.

Method parameters:
Name Type Argument Description
event String <optional>

Name of event to unsubsribe to.

listener Function <optional>

Listener to remove.

Details
Since Source
3.0.0 node_modules/js-data/src/Component.js, line 180
Inherited From:
Examples
// Remove a particular listener for a particular event
collection.off('add', handler)
// Remove all listeners for a particular event
record.off('change')
// Remove all listeners to all events
store.off()

on(event, listener, ctx)

Register a new event listener on this Component.

Method parameters:
Name Type Argument Description
event String

Name of event to subsribe to.

listener Function

Listener function to handle the event.

ctx * <optional>

Optional content in which to invoke the listener.

Details
Since Source
3.0.0 node_modules/js-data/src/Component.js, line 147
Inherited From:
Examples
// Listen for all "afterCreate" events in a DataStore
store.on('afterCreate', (mapperName, props, opts, result) => {
  console.log(mapperName) // "post"
  console.log(props.id) // undefined
  console.log(result.id) // 1234
})
store.create('post', { title: 'Modeling your data' }).then((post) => {
  console.log(post.id) // 1234
})
// Listen for the "add" event on a collection
collection.on('add', (records) => {
  console.log(records) // [...]
})
// Listen for "change" events on a record
post.on('change', (record, changes) => {
  console.log(changes) // { changed: { title: 'Modeling your data' } }
})
post.title = 'Modeling your data'

POST(url, data, config, opts)

Make a POST request.

Method parameters:
Name Type Argument Description
url *

The url for the request.

data Object

Payload for the request.

config Object

Request configuration options.

opts Object <optional>

Configuration options.

Return value:
Type Description
Promise Unspecified
Details
Source
src/index.js, line 831

PUT(url, data, config, opts)

Make a PUT request.

Method parameters:
Name Type Argument Description
url *

The url for the request.

data Object

Payload for the request.

config Object

Request configuration options.

opts Object <optional>

Configuration options.

Return value:
Type Description
Promise Unspecified
Details
Source
src/index.js, line 868

queryTransform(mapper, params, opts)

Transform the querystring object before it is serialized. This doesn't do anything by default.

Method parameters:
Name Type Description
mapper Object

The Mapper that triggered the request.

params *

The querystring object.

opts *

Configuration options

Return value:
Type Description
*

Transformed params.

Details
Source
src/index.js, line 905

respond(response, opts)

Method parameters:
Name Type Description
response Object

Response object.

opts Object

Configuration options. return {Object} If opts.raw == true then return response, else return response.data.

Inherited From:

responseError(err, config, opts)

Error handler invoked when the promise returned by HttpAdapter#http is rejected. Default implementation is to just return the error wrapped in a rejected Promise, aka rethrow the error. HttpAdapter#http is called by HttpAdapter#HTTP.

Method parameters:
Name Type Description
err *

The error that HttpAdapter#http rejected with.

config Object

The config argument that was passed to HttpAdapter#HTTP.

opts *

The opts argument that was passed to HttpAdapter#HTTP.

Return value:
Type Description
Promise Unspecified
Details
Source
src/index.js, line 927

serialize(mapper, data, opts)

Serialize request data. This doesn't do anything by default.

Method parameters:
Name Type Description
mapper Object

The Mapper that triggered the request.

data Object

The request payload.

opts *

Configuration options.

Return value:
Type Description
*

Serialized data.

Details
Source
src/index.js, line 944

sum(mapper, field, query, opts)

Retrieve the sum of the field of the records that match the selection query.

Method parameters:
Name Type Argument Description
mapper Object

The mapper.

field String

The field to sum.

query Object

Selection query.

opts Object <optional>

Configuration options.

Properties
Name Type Argument Default Description
params String <optional>

Querystring parameters.

suffix String <optional>
HttpAdapter#suffix

See HttpAdapter#suffix.

Return value:
Type Description
Promise Unspecified
Details
Source Overrides
src/index.js, line 965 Adapter#sum

update(mapper, id, props, opts)

Perform an update. Makes a PUT request by default.

Method parameters:
Name Type Argument Description
mapper Object

The Mapper for the request.

id *

The primary key of the record being updated.

props *

The update payload.

opts Object <optional>

Configuration options.

Return value:
Type Description
Promise Unspecified
Details
Source Overrides
src/index.js, line 992 Adapter#update

updateAll(mapper, props, query, opts)

Perform an update against records that match the selection query. Makes a PUT request by default.

Method parameters:
Name Type Argument Description
mapper Object

The Mapper for the request.

props Object

The update payload.

query Object

The selection query. See http://www.js-data.io/docs/query-syntax.

opts Object <optional>

Configuration options.

Return value:
Type Description
Promise Unspecified
Details
Source Overrides
src/index.js, line 1011 Adapter#updateAll

updateMany(mapper, records, opts)

Update multiple individual records in a batch.

Method parameters:
Name Type Argument Description
mapper Object

The Mapper for the request.

records Array

Array of property objects to send as the payload. Each must contain the primary key of the record to be updated.

opts Object <optional>

Configuration options.

Properties
Name Type Argument Default Description
params String <optional>

Querystring parameters.

suffix String <optional>
HttpAdapter#suffix

See HttpAdapter#suffix.

Return value:
Type Description
Promise Unspecified
Details
Source Overrides
src/index.js, line 1033 Adapter#updateMany