Skip to main content

Getting started

We provide an enhanced OpenAPI client based on typescript-fetch written in typescript for integration with the Nile API.

Installation

yarn add @theniledev/js
npm install @theniledev/js

Basic usage

import Nile from "@theniledev/js";

const nile = Nile({
basePath: "<path_to_nile_api>",
workspace: "<workspace_id>",
});

// log in to set the auth token
await nile.developers.loginDeveloper({
loginInfo: {
email: "dev@dev.dev",
password: "123",
},
});

// set the global token as a developer
nile.authToken = nile.developers.authToken;

// validate the developer token
const validated = await nile.developers.validateDeveloper({
token: { token: nile.authToken },
});
console.log(validated);
info

If you're using node, use Nile.default for your initial call. Since the library uses fetch, using the library requires node version > 17.5. You can run with the experimental flag via node --experimental-fetch index.mjs

The base functions and API integrations can be found in the client section.

Obtaining a workspace id

To use the SDK, a url to the nile backend and a workspace identifier are needed.

When a developer signs up, a workspace is automatically created. To obtain the workspace id, an authenticated request to the /workspaces endpoint must be made.

import Nile from "@theniledev/js";

const nile = Nile({ basePath: "http://localhost:8080" });

// create a new developer
await nile.developers.createDeveloper({
createUserRequest: {
email: "dev@dev.dev",
password: "123",
},
});

// log in
await nile.developers.loginDeveloper({
loginInfo: {
email: "dev@dev.dev",
password: "123",
},
});

// set the global token as a developer
nile.authToken = nile.developers.authToken;

// create a workspace
await nile.workspaces.createWorkspace({
createOrganizationRequest: { name: "My Workspace" },
});

console.log(await nile.workspaces.listWorkspaces());

Supported libraries

In addition the the standard Javascript client, we support the following frameworks:

@theniledev/react