Module: js-data-http

Registered as js-data-http in NPM and Bower. The build of js-data-http that works on Node.js is registered in NPM as js-data-http-node. The build of js-data-http that does not bundle axios is registered in NPM and Bower as js-data-fetch.

Details
Source
src/index.js, line 1209
Examples

var HttpAdapter = window.JSDataHttp.HttpAdapter
var adapter = new HttpAdapter()

var HttpAdapter = require('js-data-Http').HttpAdapter
var adapter = new HttpAdapter()

import {HttpAdapter} from 'js-data-Http'
const adapter = new HttpAdapter()

define('myApp', ['js-data-Http'], function (JSDataHttp) {
  var HttpAdapter = JSDataHttp.HttpAdapter
  var adapter = new HttpAdapter()

  // ...
})

Members


<static> HttpAdapter

Details
Source See
src/index.js, line 180

<static> version

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

Details
Type Source
Object src/index.js, line 1193
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.

Methods


<static> addAction(name, opts)

Add an Http actions to a mapper.

Method 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>
Return value:
Type Description
Function

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

Details
Source
src/index.js, line 1046
Example
// CommonJS
var JSData = require('js-data')
// It is recommended to use DataStore in the browser
var DataStore = JSData.DataStore

var JSDataHttp = require('js-data-http')
var HttpAdapter = JSDataHttp.HttpAdapter
var addAction = JSDataHttp.addAction

var adapter = new HttpAdapter()
var store = new DataStore()

store.registerAdapter('http', adapter, { default: true })
store.defineMapper('school')

// GET /reports/schools/:school_id/teachers
addAction('getTeacherReports', {
  basePath: 'reports/schools',
  pathname: 'teachers',
  method: 'GET'
})(store.getMapper('school'))

// /reports/schools/1234/teachers
store.getMapper('school').getTeacherReports(1234).then(function (response) {
  // ...
})

<static> addActions(opts)

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

Method 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.

Return value:
Type Description
Function

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

Details
Source
src/index.js, line 1142
Example
// CommonJS
var JSData = require('js-data')
// It is recommended to use DataStore in the browser
var DataStore = JSData.DataStore

var JSDataHttp = require('js-data-http')
var HttpAdapter = JSDataHttp.HttpAdapter
var addActions = JSDataHttp.addActions

var adapter = new HttpAdapter()
var store = new DataStore()

store.registerAdapter('http', adapter, { default: true })
store.defineMapper('school')

addActions({
  // GET /reports/schools/:school_id/teachers
  getTeacherReports: {
    basePath: 'reports/schools',
    pathname: 'teachers',
    method: 'GET'
  }
})(store.getMapper('school'))

// /reports/schools/1234/teachers
store.getMapper('school').getTeacherReports(1234).then(function (response) {
  // ...
})