# Interact with data
# Install SDKs
- JavaScript
- Python
- cURL
// node only
npm install jexia-sdk-js node-fetch ws --save
// web
npm install jexia-sdk-js --save
# Make request
Now let's make simple CRUD to access our Dataset. For this, you can use the REST API or one of our SDKs. Our JS SDK is built on top of the RxJS library, so you can use all the power of this library. Other SDKs can be found on our GitHub.
- JavaScript
- Python
- cURL
Below you can see an example with all the modules imported from SDK. If you do not need to access Filesets, Project Users (UMSModule) or real-time events, feel free to skip importing them.
import {
jexiaClient,
dataOperations, // To work with Datasets
fileOperations, // To work with Filesets
UMSModule, // To work with Project Users
realTime // To get real-time notification for data changes and work channels
} from "jexia-sdk-js/node";
const ds = dataOperations();
const jfs = fileOperations();
const ums = new UMSModule();
const rtc = realTime();
// You need to use your API Key / API Secret which is generated within your Jexia application.
// Do not forget to create a Policy for your API and set the proper restrictions!
// In addition to key and secret, you need to provide either projectID and zone OR just provide projectURL
jexiaClient().init({
projectID: "PROJECT_ID",
key: "API_KEY",
secret: "API_SECRET",
/**
* Zone parameter was introduced in v5.2.0
* If your project uses a previous version it will keep working for a while.
* You can find you project zone inside "Settings" section of your project.
*/
zone: "PROJECT_ZONE",
}, ds, /* pass any other modules you need like jfs, ums, rtc */);
// or
jexiaClient().init({
projectURL: "PROJECT_URL", // you can find it in your project settings
key: "API_KEY",
secret: "API_SECRET",
}, ds);
// Now you can run any CRUD operations for your Datasets
const orders = ds.dataset("orders");
const archive = ds.dataset("arch");
const selectQuery = orders
.select()
.where(field => field("dislike").isEqualTo(true));
// const insertQuery = orders.insert([order1, order2]);
// const updateQuery = orders.update([{ title: "Updated title" }]);
// const deleteQuery = orders.delete();
selectQuery.subscribe(records => {
// You will always get an array of created records, including their
// generated IDs (even when inserting a single record)
},
error => {
// If something goes wrong, you'll get an IRequestError object
});
# Work from browser
You can work with Jexia platform directly from browser. For this you need to import Jexia SDK through unpkg
<html>
<head>
<script src="https://unpkg.com/jexia-sdk-js/bundle/browser.umd.min.js"></script>
</head>
and then do similar commands to get data. Below you can find example:
<html>
<head>
<script src="https://unpkg.com/jexia-sdk-js/bundle/browser.umd.min.js"></script>
</head>
<body>
<i>loading...</i>
<ul></ul>
<script type="text/javascript">
window.onload = function() {
if (!jexia) {
throw new Error("Please inform support team of Jexia.");
}
// Initialize dataOperationsModule
const dataModule = jexia.dataOperations();
const credentials = {
projectID: "<your-project-id>",
key: "<your-project-api-key>",
secret: "<your-project-api-secret>",
zone: "<your-project-zone>",
};
jexia.jexiaClient().init(credentials, dataModule);
const postsList = document.querySelector("ul");
dataModule.dataset("posts")
.select()
.subscribe(
(posts) => {
posts.forEach((post) => {
const postTitle = document.createElement("li");
postTitle.innerText = post.title;
postsList.appendChild(postTitle);
});
},
(errors)=>{console.log(errors)}
)
}
</script>
</body>
</html>
# Events
As we try to handle "almost" everything for you, there are still cases where you need to act on actions/events when something happens. Therefore you can use the event system of the SDK, for example to execute custom code on a login.
Currently, we have the following events available for you.
token:login
when you login with yoursecret
andkey
token:refresh
when your token got expired and the SDK is refreshing your tokentoken:refreshFailed
when refreshing a token failedums:login
when a UMS user is sign-inums:switchUser
when a UMS user is switchingums:logout
when a UMS user is sign-out
- JavaScript
import {
jexiaClient,
} from "jexia-sdk-js/browser";
const client = jexiaClient().init({
... your project configs
}, /* pass any modules you need like ds jfs, ums, rtc */);
client.on(<your-event-name>, <custom-function>);
// for example when token refresh has been failed (SDK does not know what to do)
client.on('token:refreshFailed', () => location.href = '/login');