Class: HttpAdapter

HttpAdapter


new HttpAdapter(opts)

HttpAdapter class.

Parameters:
Name Type Argument Description
opts Object <optional>

Configuration options.

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

TODO

debug boolean <optional>
false

TODO

forceTrailingSlash boolean <optional>
false

TODO

http Object <optional>
axios

TODO

httpConfig Object <optional>
{}

TODO

suffix string <optional>
''

TODO

useFetch boolean <optional>
false

TODO

Source:

Members


<static> version :Object

Details of the current version of the js-data-http module.

Type:
  • Object
Properties:
Name Type Description
version.full string

The full semver value.

version.major number

The major version number.

version.minor number

The minor version number.

version.patch number

The patch version number.

version.alpha string | boolean

The alpha version value, otherwise false if the current version is not alpha.

version.beta string | boolean

The beta version value, otherwise false if the current version is not beta.

Source:

basePath :string

Type:
  • string
Source:

forceTrailingSlash :boolean

Type:
  • boolean
Default Value:
  • false
Source:

http :function

Type:
  • function
Source:

httpConfig :Object

Type:
  • Object
Source:

suffix :string

Type:
  • string
Source:

useFetch :boolean

Type:
  • boolean
Default Value:
  • false
Source:

Methods


<static> addAction(name, opts)

Add an Http actions to a mapper.

Parameters:
Name Type Argument Description
name string

Name of the new action.

opts Object <optional>

Action configuration

Properties
Name Type Argument Description
adapter string <optional>
pathname string <optional>
request function <optional>
response function <optional>
responseError function <optional>
Source:
Returns:

Decoration function, which should be passed the mapper to decorate when invoked.

Type
function

<static> addActions(opts)

Add multiple Http actions to a mapper. See HttpAdapter.addAction for action configuration options.

Parameters:
Name Type Description
opts Object.<string, Object>

Object where the key is an action name and the value is the configuration for the action.

Source:
Returns:

Decoration function, which should be passed the mapper to decorate when invoked.

Type
function

<static> extend(instanceProps, classProps)

Alternative to ES6 class syntax for extending HttpAdapter.

ES6:

class MyHttpAdapter extends HttpAdapter {
  deserialize (Model, data, opts) {
    const data = super.deserialize(Model, data, opts)
    data.foo = 'bar'
    return data
  }
}

ES5:

var instanceProps = {
  // override deserialize
  deserialize: function (Model, data, opts) {
    var Ctor = this.constructor
    var superDeserialize = (Ctor.__super__ || Object.getPrototypeOf(Ctor)).deserialize
    // call the super deserialize
    var data = superDeserialize(Model, data, opts)
    data.foo = 'bar'
    return data
  },
  say: function () { return 'hi' }
}
var classProps = {
  yell: function () { return 'HI' }
}

var MyHttpAdapter = HttpAdapter.extend(instanceProps, classProps)
var adapter = new MyHttpAdapter()
adapter.say() // "hi"
MyHttpAdapter.yell() // "HI"
Parameters:
Name Type Argument Description
instanceProps Object <optional>

Properties that will be added to the prototype of the subclass.

classProps Object <optional>

Properties that will be added as static properties to the subclass itself.

Source:
Returns:

Subclass of HttpAdapter.

Type
Object

afterDEL(url, config, opts, response)

Parameters:
Name Type Description
url string
config Object
opts Object
response Object
Source:

afterGET(url, config, opts, response)

Parameters:
Name Type Description
url string
config Object
opts Object
response Object
Source:

afterHTTP(config, opts, response)

Parameters:
Name Type Description
config Object
opts Object
response Object
Source:

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

Parameters:
Name Type Description
url string
data Object
config Object
opts Object
response Object
Source:

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

Parameters:
Name Type Description
url string
data Object
config Object
opts Object
response Object
Source:

beforeDEL(url, config, opts)

Parameters:
Name Type Description
url Object
config Object
opts Object
Source:

beforeGET(url, config, opts)

Parameters:
Name Type Description
url Object
config Object
opts Object
Source:

beforeHTTP(config, opts)

Parameters:
Name Type Description
config Object
opts Object
Source:

beforePOST(url, data, config, opts)

Parameters:
Name Type Description
url Object
data Object
config Object
opts Object
Source:

beforePUT(url, data, config, opts)

Parameters:
Name Type Description
url Object
data Object
config Object
opts Object
Source:

count(mapper, query, opts)

Retrieve the number of records that match the selection query.

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>

TODO

suffix string <optional>
HttpAdapter#suffix

TODO

Source:
Returns:
Type
Promise

create(mapper, props, opts)

Create a new the record from the provided props.

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>

TODO

suffix string <optional>
HttpAdapter#suffix

TODO

Source:
Returns:
Type
Promise

createMany(mapper, props, opts)

Create multiple new records in batch.

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>

TODO

suffix string <optional>
HttpAdapter#suffix

TODO

Source:
Returns:
Type
Promise

DEL(url, config, opts)

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

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.

Source:
Returns:
Type
Promise

deserialize(mapper, response, opts)

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

Parameters:
Name Type Description
mapper Object

The mapper used for the operation.

response Object

Response object from HttpAdapter#HTTP.

opts Object

Configuration options.

Source:
Returns:

Deserialized data.

Type
Object | Array

destroy(mapper, id, opts)

Destroy the record with the given primary key.

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>

TODO

suffix string <optional>
HttpAdapter#suffix

TODO

Source:
Returns:
Type
Promise

destroyAll(mapper, query, opts)

Destroy the records that match the selection query.

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>

TODO

suffix string <optional>
HttpAdapter#suffix

TODO

Source:
Returns:
Type
Promise

error(args)

Log an error.

Parameters:
Name Type Argument Description
args * <optional>
<repeatable>

Arguments to log.

Source:

fetch(config, opts)

Make an Http request using window.fetch.

Parameters:
Name Type Argument 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.

opts Object <optional>

Configuration options.

Source:

find(mapper, id, opts)

Retrieve the record with the given primary key.

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>

TODO

suffix string <optional>
HttpAdapter#suffix

TODO

Source:
Returns:
Type
Promise

findAll(mapper, query, opts)

Retrieve the records that match the selection query.

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>

TODO

suffix string <optional>
HttpAdapter#suffix

TODO

Source:
Returns:
Type
Promise

GET(url, config, opts)

TODO

Parameters:
Name Type Argument Description
url string

The url for the request.

config Object

Request configuration options.

opts Object <optional>

Configuration options.

Source:
Returns:
Type
Promise

getEndpoint(mapper, id, opts)

Parameters:
Name Type Description
mapper Object

TODO

id *

TODO

opts boolean

TODO

Source:
Returns:

Full path.

Type
string

getPath(method, mapper, id, opts)

Parameters:
Name Type Argument Description
method string

TODO

mapper Object

TODO

id string | number <nullable>

TODO

opts Object

Configuration options.

Source:

HTTP(config, opts)

Make an Http request.

Parameters:
Name Type Argument Description
config Object

Request configuration options.

opts Object <optional>

Configuration options.

Source:
Returns:
Type
Promise

POST(url, data, config, opts)

TODO

Parameters:
Name Type Argument Description
url *

TODO

data Object

TODO

config Object

TODO

opts Object <optional>

Configuration options.

Source:
Returns:
Type
Promise

PUT(url, data, config, opts)

TODO

Parameters:
Name Type Argument Description
url *

TODO

data Object

TODO

config Object

TODO

opts Object <optional>

Configuration options.

Source:
Returns:
Type
Promise

queryTransform(mapper, params, opts)

TODO

Parameters:
Name Type Description
mapper Object

TODO

params *

TODO

opts *

TODO

Source:
Returns:

Transformed params.

Type
*

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.

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.

Source:
Returns:
Type
Promise

serialize(mapper, data, opts)

TODO

Parameters:
Name Type Description
mapper Object

TODO

data Object

TODO

opts *

TODO

Source:
Returns:

Serialized data.

Type
*

sum(mapper, field, query, opts)

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

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>

TODO

suffix string <optional>
HttpAdapter#suffix

TODO

Source:
Returns:
Type
Promise

update(mapper, id, props, opts)

TODO

Parameters:
Name Type Argument Description
mapper Object

TODO

id *

TODO

props *

TODO

opts Object <optional>

Configuration options.

Source:
Returns:
Type
Promise

updateAll(mapper, props, query, opts)

TODO

Parameters:
Name Type Argument Description
mapper Object

TODO

props Object

TODO

query Object

TODO

opts Object <optional>

Configuration options.

Source:
Returns:
Type
Promise

updateMany(mapper, records, opts)

Update multiple records in batch.

HttpAdapter#beforeUpdateMany will be called before calling HttpAdapter#PUT. HttpAdapter#afterUpdateMany will be called after calling HttpAdapter#PUT.

Parameters:
Name Type Argument Description
mapper Object

The mapper.

records Array

Array of property objects to send as the payload.

opts Object <optional>

Configuration options.

Properties
Name Type Argument Default Description
params string <optional>

TODO

suffix string <optional>
HttpAdapter#suffix

TODO

Source:
Returns:
Type
Promise