Droplit SDK

Access the Droplit system via JavaScript and TypeScript.

Overview

The Droplit SDK provides convenient access to the Droplit system from within a JavaScript or TypeScript environment. The SDK supports several REST calls to many of the the Droplit API endpoints. The SDK function for performing a certain action is included within that action's documentation page.

Installation

  1. Install NodeJS for Windows, MacOS, or Linux.
  2. Use NPM to install the droplit SDK: npm install droplit-sdk --save.

Setting up the SDK for Use

In order to make use of the droplit SDK within the Node prompt, or in any JavaScript or TypeScript program, some preliminary steps must first be completed.

  1. The SDK must be required.
var droplitSDK = require('droplit-sdk');
  1. An instance of the SDK must then be created.
var droplit = droplitSDK.instance();
  1. Initialize the new instance with a base URI, an authorization token, and, optionally, a client ID.
droplit.initialize("https://ioe.droplit.io", "AUTH_TOKEN", "CLIENT_ID");

Using the SDK

The Droplit SDK may be loaded into Node, or included in any JavaScript or TypeScript file, which enables the Droplit system to be easily used in a JavaScript or TypeScript environment. Since the SDK makes calls to the Droplit API via REST commands, each SDK function returns a JavaScript Promise to allow for asynchronous operation. Once the Promise is fulfilled, a JSON object containing both the HTTP status of the request and information from the Droplit system is returned.

Such ease of use within the environments of JavaScript and TypeScript is helpful when creating webpages to display information from the Droplit system or when building JavaScript and TypeScript applications.

Examples

Get Environments

Get the Promise for a list of all the environments within a particular ecosystem:

droplit.environments.list("C594b89aea18568c408c3ad24");

Once that Promise is fulfilled, the following JSON object is returned:

{ 
    status: 200,
    statusText: 'OK',
    responseType: 'Success',
    body: {
        items: [  {
            id: 'E598341bcba0e6139691dcda1',
            domain: 'demo-environment1',
            meta: { 
                 '$label': 'demo1',
                 '$authProvider': '5a2b8808c9e4bcab384ec2f3' 
             },
            createdAt: '2017-10-21T18:15:10.542Z' 
        }, { 
            id: 'E5978aa5917b910be375c237c',
            domain: 'demo-environment2',
            meta: { 
                '$authProvider': '5a56fbe2aef62bb7085dcd25' 
            },
            createdAt: '2017-10-21T18:17:07.531Z' 
        } ] 
    }
}

status is the HTTP status of the request, statusText is the description accompanying the HTTP status, resonseType is the type of the response ("Success", "Failure", etc.), and body is the information returned by the Droplit system.

Create a User Token

Get the Promise for the creation of a user token:

droplit.users.createToken("C594b89aea18568c408c3ad24", "demo_user", 3600, "FixedTtl");

Once the Promise is fulfilled, the following JSON object is returned:

{ 
    status: 201,
    statusText: 'Created',
    responseType: 'Created',
    body: {
        token: '_y2OVdlQNKzhOo4j9Sqck5pVAwfJXw6OuGwdTsVNVuoy2yHffnALs6- 
                     GROT21RciDjQauxAg51sYjQnhM9vPaxcCAGY2z0hUQQDE- 
                     nshUpJWgQhGGQAhZj3G5JYOoegC5' 
    }
}