JavaScript

Overview

This library contains all the API calls needed to communicate with the HAT.
  • Authentication
  • Fetch Applications, Data Plugs and Data Debits
  • Read and write data to endpoints
  • File API

Setting Up Environment

Supported Environments

The @dataswift/hat-js library works in all modern browsers. Some older browsers do not support all the features required. If you want to support these browsers you need to load polyfill for Promise.

Installation

Install the @dataswift/hat-js package via npm or pull from our CDN.
NPM installation
1
npm install @dataswift/hat-js
Copied!
CDN Link
1
<script src="https://cdn.dataswift.io/libs/hatjs/hat-0.3.0.min.js"></script>
Copied!

Usage

Importing

ES6
1
import { HatClient } from "@dataswift/hat-js";
Copied!
ES5 Modules
1
var HatClient = require("@dataswift/hat-js").HatClient;
Copied!

Initialisation

Configuration type:
1
interface HatClientConfig {
2
apiVersion?: string; // Api Version for the HAT. eg. v2.6
3
hatDomain?: string; // The HAT domain of the user. eg. testing.hubat.net
4
token?: string; // The Application token.
5
secure?: boolean; // If you want to run the HAT locally, you have to modify this field to 'false'.
6
onTokenChange?: Function;
7
}
Copied!
Example:
1
const config = {
2
token: "<access-token>",
3
apiVersion: 'v2.6',
4
secure: true,
5
onTokenChange: (newToken) => storeNewToken(newToken)
6
};
7
8
const hat = new HatClient(config);
Copied!