Initialization and authentication

Before you can start using the datasets within your project, you will need to authenticate. In order to do this, you will need to provide your project URL and API keys that holds policies. API keys consist out of a key and a secret. Policies describe what access is provided to a dataset. You can just pass in your project URl and the API keys as described in the example below and the SDK will authenticate behind the scenes. Because you have created policies and assigned them to an API key, you don't need to worry about authorization, it's handled by the platform.

Example

const sdk = require('jexia-sdk-js/node');
const fetch = require("node-fetch");
 
let initializedClientPromise = sdk.jexiaClient(fetch).init({appUrl: "your Jexia Project URL", key: "<your-apikey>", secret: "<your-secret>"});
initializedClientPromise.then( (initializedClient) => {
  // you have been succesfully logged in!
  // you can start using the initializedClient variable here
}).catch( (error) => {
  // uh-oh, there was a problem logging in, check the error.message for more info
});

Advanced users

The jexiaClient() function will return an instance of the Client class. On Node.JS, you will need to provide a fetch standard compliant function as a parameter. You will need to add a compatible dependency to your project. For development of the SDK we've used node-fetch

The Module system

The Jexia SDK is built as a set of modules (or plugins) structured around a core entity (the Client class used above). In order to use a module you need to:

  • initialize it
  • pass it to the Client when calling the .init() method

Probably the most useful module is the Data Operation Module (DataOperationsModule class). The example below will show how to initialize the SDK using this module. Follow the dataModule variable to see how this mechanism works.

const sdk = require('jexia-sdk-js/node');
const fetch = require("node-fetch");
 
let dataModule = sdk.dataOperations();
 
let initializedClientPromise = sdk.jexiaClient(fetch).init({appUrl: "your Jexia App URL", key: "<your-apikey>", secret: "<your-secret>"}, dataModule);
initializedClientPromise.then( (initializedClient) => {
  // you have been succesfully logged in!
  // you can start using the dataModule variable to operate on records here
}).catch( (error) => {
  // uh-oh, there was a problem logging in, check the error.message for more info
});