@nonokko/client v1.2.3-alpha.1
nonokko JavaScript/TypeScript client library
Introduction
The nonokko JavaScript Client Library provides a seamless way to interact with nonokko endpoints from your JavaScript or TypeScript applications. With built-in support for various platforms, it ensures consistent behavior across web, Node.js, and React Native environments.
Getting started
Before diving into the client-specific features, ensure you've set up your credentials:
import { nonokko } from "@nonokko/client";
nonokko.config({
// Can also be auto-configured using environment variables:
// Either a single NONOKKO_KEY or a combination of NONOKKO_KEY_ID and NONOKKO_KEY_SECRET
credentials: "NONOKKO_KEY_ID:NONOKKO_KEY_SECRET",
});Note: Ensure you've reviewed the nonokko getting started guide to acquire your credentials and register your functions. Also, make sure your credentials are always protected. See the ../proxy package for a secure way to use the client in client-side applications.
Running functions with nonokko.run
The nonokko.run method is the simplest way to execute a function. It returns a promise that resolves to the function's result:
const result = await nonokko.run("my-function-id", {
input: { foo: "bar" },
});Long-running functions with nonokko.subscribe
The nonokko.subscribe method offers a powerful way to rely on the queue system to execute long-running functions. It returns the result once it's done like any other async function, so your don't have to deal with queue status updates yourself. However, it does support queue events, in case you want to listen and react to them:
const result = await nonokko.subscribe("my-function-id", {
input: { foo: "bar" },
onQueueUpdate(update) {
if (update.status === "IN_QUEUE") {
console.log(`Your position in the queue is ${update.position}`);
}
},
});More features
The client library offers a plethora of features designed to simplify your journey with nonokko. Dive into the official documentation for a comprehensive guide.
8 months ago