{"_id":"5b60c390a873bd00033b3262","project":"568bdc1483d2061900d86cdc","version":{"_id":"59a72290d61777001b6c42c3","project":"568bdc1483d2061900d86cdc","__v":33,"createdAt":"2017-08-30T20:39:44.453Z","releaseDate":"2017-08-30T20:39:44.453Z","categories":["59a7236e3fe4d90025117c10","59a72eb6cb0db3001b84cfe2","59a734eb757d030019b85af8","59c0243b1b2d07001a9d2b76","59c035e42126e10028effb12","59c06c40df5b3c0010584a13","59c1a5852cabe5002641a3e7","59c2fb00b2b45c0010b7a3d7","59c32ceb9aea850010ac4130","59c32e6e190c90003cb0d12f","59c33affb2b45c0010b7aa23","59c7dfa457bd8200105444dc","59c7e975c50cf30010d712a0","59cffdef0cd4dd0010294d54","59d0622ca91a810032c8f60c","59d06733c1aec60026253065","59d174d44ac471001a07b123","59d5a5e323e6e800103defb2","59ecf1d8ed507c001c52b255","59f76fef8581dc0010593e6f","5a0c003680a35b0012c35db0","5a8358722e78660075e45f42","5a846645b5ec3a001203517e","5b258091bc7a6700033b9cb5","5b26e48e024807000315a740","5b44edff3306680003663f5c","5b468abd3d4a9e0003789111","5b468d8f3dcb6a0003c6e374","5b47b0b93d4a9e000378a33a","5b538d114ea24f00033c726f","5b6a0efe402b32000336c33f","5bba5e5d7ba7710003bd902a","5bc2703349ac3a0013eec3e5"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"0.0.0","version":"0"},"category":{"_id":"59a734eb757d030019b85af8","project":"568bdc1483d2061900d86cdc","version":"59a72290d61777001b6c42c3","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-08-30T21:58:03.883Z","from_sync":false,"order":7,"slug":"rest-api-usage","title":"REST API Usage"},"user":"5a6a26281895510045b2cd40","githubsync":"","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2018-07-31T20:16:16.250Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"# Overview\n\nThe 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.\n\n# Installation\n\n1. Install NodeJS for [Windows](https://docs.droplit.io/docs/install-nodejs-on-windows), [MacOS](https://docs.droplit.io/docs/install-nodejs-on-mac-os), or [Linux](https://docs.droplit.io/docs/install-nodejs-on-linux).\n2. Use NPM to install the droplit SDK: `npm install droplit-sdk --save`.\n\n# Setting up the SDK for Use\n\nIn 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.\n\n1. The SDK must be required.\n```\nvar droplitSDK = require('droplit-sdk');\n```\n\n2. An instance of the SDK must then be created.\n```\nvar droplit = droplitSDK.instance();\n```\n\n3. Initialize the new instance with a base URI, an authorization token, and, optionally, a client ID.\n```\ndroplit.initialize(\"https://ioe.droplit.io\", \"AUTH_TOKEN\", \"CLIENT_ID\");\n```\n\n# Using the SDK\n\nThe 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.\n\nSuch 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.\n\n## Examples\n\n### Get Environments\n\nGet the Promise for a list of all the environments within a particular ecosystem:\n```\ndroplit.environments.list(\"C594b89aea18568c408c3ad24\");\n```\n\nOnce that Promise is fulfilled, the following JSON object is returned:\n```\n{ \n    status: 200,\n    statusText: 'OK',\n    responseType: 'Success',\n    body: {\n        items: [  {\n            id: 'E598341bcba0e6139691dcda1',\n            domain: 'demo-environment1',\n            meta: { \n                 '$label': 'demo1',\n                 '$authProvider': '5a2b8808c9e4bcab384ec2f3' \n             },\n            createdAt: '2017-10-21T18:15:10.542Z' \n        }, { \n            id: 'E5978aa5917b910be375c237c',\n            domain: 'demo-environment2',\n            meta: { \n                '$authProvider': '5a56fbe2aef62bb7085dcd25' \n            },\n            createdAt: '2017-10-21T18:17:07.531Z' \n        } ] \n    }\n}\n```\n`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.\n\n### Create a User Token\n\nGet the Promise for the creation of a user token:\n```\ndroplit.users.createToken(\"C594b89aea18568c408c3ad24\", \"demo_user\", 3600, \"FixedTtl\");\n```\n\nOnce the Promise is fulfilled, the following JSON object is returned:\n```\n{ \n    status: 201,\n    statusText: 'Created',\n    responseType: 'Created',\n    body: {\n        token: '_y2OVdlQNKzhOo4j9Sqck5pVAwfJXw6OuGwdTsVNVuoy2yHffnALs6- \n                     GROT21RciDjQauxAg51sYjQnhM9vPaxcCAGY2z0hUQQDE- \n                     nshUpJWgQhGGQAhZj3G5JYOoegC5' \n    }\n}\n```","excerpt":"Access the Droplit system via JavaScript and TypeScript.","slug":"droplit-sdk","type":"basic","title":"Droplit SDK"}

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](https://docs.droplit.io/docs/install-nodejs-on-windows), [MacOS](https://docs.droplit.io/docs/install-nodejs-on-mac-os), or [Linux](https://docs.droplit.io/docs/install-nodejs-on-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'); ``` 2. An instance of the SDK must then be created. ``` var droplit = droplitSDK.instance(); ``` 3. 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' } } ```