koxy-js
v1.1.1
Published
Run your serverless API flows and functions in 35 regions around the world from your front-end with real-time support
Downloads
39
Maintainers
Readme
Koxy JS by Koxy AI
Koxy AI is a no-code platform helps you build your AI-powered serverless back-end served edge-close to users from 35 regions, and Koxy JS is a client library to integrate your Koxy back-end in your front-end.
Installation
npm install koxy-js
Usage
First go to Koxy AI platform, sign up and create your Koxy Cloudspace. You can create API flows and cloud functions in the platform and run them from your front-end as described below: (full docs)
import { koxyAPI } from 'koxy-js';
// Initialize (replace CLOUDSPACE_TOKEN with your Cloudspace token)
const api = new koxyAPI("CLOUDSPACE_TOKEN");
// Set request parameters
const parameters = {
"param1": "value1"
};
// Run API flow (replace "main" with the flow name you want to run)
const data = await api.run("main", parameters);
// Run cloud function
const functionData = await api.runFunction("function_name");
Send Parameters and headers
You can send parameters and headers to your API flows. example:
import { koxyAPI } from 'koxy-js';
// Initialize (replace CLOUDSPACE_TOKEN with your Cloudspace token)
const api = new koxyAPI("CLOUDSPACE_TOKEN");
// Set request parameters
const parameters = {
"param1": "value1"
};
// Set request headers
const headers = {
"customHeader": "headerValue"
};
// Run API flow (replace "main" with the flow name you want to run)
const data = await api.run("main", parameters, headers);
Currently, You can't send parameters or headers to cloud functions.
Real-time
Real-time in Koxy AI is built on top of GunDB, It's decentralized and has no limits. After creating a Cloudspace in Koxy AI, you can go to Real-time channels from the sidebar to get your real-time ROOT_ID and manage your real-time channels. This feature is totally free with no limits at all.
import { koxyRealtime } from 'koxy-js';
// Setup real-time channel (You can get your root ID from your Cloudspace's tokens page)
const channel = new koxyRealtime(
"ROOT_ID",
"room_123"
);
// Put node to the channel and listen to it
channel.asyncPut("message_1694453447561", {
"message": "Hello friend",
"owner": "user_092",
"date": 1694453447561
}, function (data) {
console.log(data);
})
// Put node to the channel
channel.put("message_1694453447561", {
"message": "Hello friend",
"owner": "user_092",
"date": 1694453447561
});
// Listen to data changes in the whole channel
channel.on("room_123", function (data) {
console.log(data);
});
How to build your API flows
After creating your Cloudspace, go to API Flows from the sidebar, and create your first flow, just name it and you're good to go, then you can use the drag-and-drop builder to build your flow's functionality, when you're done your can save and deploy your flow to the cloud.
How to build your cloud functions (demo)
After creating your Cloudspace, go to Functions from the sidebar, and create your first function, just name it and you're good to go, now you code your cloud function, deploy it with one click and you can run it from your front-end.
Now you can run this function in the cloud from your front-end, example:
import { koxyAPI } from 'koxy-js';
// Initialize (replace CLOUDSPACE_TOKEN with your Cloudspace token)
const api = new koxyAPI("CLOUDSPACE_TOKEN");
// Run the function (replace "main_function" with your function name)
const data = await api.runFunction("main_function");
Report issues
You can support us by reporting any issues you face here
License
Built with love by Kais Radwan.