1.3.0 • Published 8 years ago

rest-data-client v1.3.0

Weekly downloads
15
License
Artistic-2.0
Repository
github
Last release
8 years ago

REST Data Client

Access your REST data APIs with custom ad-hoc queries that can be cached and reused. This package and its corresponding server component module rest-data-api are inspired by the excellent post HTTP/REST Data APIs on the Panda Strike Blog.

Installation

You will also want to set up rest-data-api to create the APIs you want to access with this module.

Node

npm install rest-data-client

Then in your code:

var RestDataClient = require('rest-data-client');

Browser

This package includes a pre-built webpack module for easy inclusion in the browser at dist/rest-data-client.js.

You can also use RawGit to include the latest version of the module for development or production environments.

Development

https://rawgit.com/neodon/rest-data-client/master/dist/rest-data-client.js

Production

https://cdn.rawgit.com/neodon/rest-data-client/master/dist/rest-data-client.js

Usage

REST Data Client is agnostic to the method you use to make API calls. You only need to give it the url for your rest-data-api setup and define a requestHandler to tell it how to make the calls.

A requestHandler can return a promise or use the resolve and reject callbacks passed to it.

jQuery

var restDataClient = new RestDataClient({
  apiUrl: '/query',
  requestHandler: function(req, resolve, reject) {
    $.ajax({
      method: req.method,
      url: req.url,
      contentType: 'application/json',
      dataType: 'json',
      data: req.body,
      error: function(jqXHR, textStatus, errorThrown) {
        // Do some error handling here and/or
        // after you create a queryTemplate or run a query
        return reject([jqXHR, textStatus, errorThrown]);
      },
      success: function(data, textStatus, jqXHR) {
        return resolve(data);
      }
    });
  }
});

Angular

var restDataClient = new RestDataClient({
  apiUrl: '/query',
  requestHandler: function(req, resolve, reject) {
    return $http({
      method: req.method,
      url: req.url,
      data: req.body
    });
  }
});

Development

1.3.0

8 years ago

1.2.0

8 years ago

1.1.3

8 years ago

1.1.2

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.1.0

8 years ago

0.0.1

8 years ago