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 1218
Examples

var HttpAdapter = window.JSDataHttp.HttpAdapter;
var httpAdapter = new HttpAdapter();

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

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

define('myApp', ['js-data-Http'], function (JSDataHttp) {
  var HttpAdapter = JSDataHttp.HttpAdapter;
  var httpAdapter = 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 1202
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 Default Description
adapter String <optional>
"http"

The name of the adapter to use.

pathname String <optional>

Set the action's pathname.

request Function <optional>

Specify a request handler to be executed before the request is made.

response Function <optional>

Specify a response handler to be executed after the response is received.

responseError Function <optional>

Specify an error handler to be executed on error.

Return value:
Type Description
Function

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

Details
Source
src/index.js, line 1055
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 httpAdapter = new HttpAdapter();
var store = new DataStore();

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

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

// /reports/schools/1234/teachers
store.getMapper('school').getTeacherReports(1234).then((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 1151
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 httpAdapter = new HttpAdapter();
var store = new DataStore();

store.registerAdapter('http', httpAdapter, { '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((response) => {
  // ...
});