backend.ai-client-js

Backend.AI Client Library for Javascript

  • Owner: lablup/backend.ai-client-js
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

Backend.AI Client for Javascript (node.js / ES6+)

Requirements

This client SDK runs on CommonJs (with node.js) / ES6-compatible Javascript runtimes with async/await supports
such as NodeJS 7+ and modern web browsers released since 2017.

This client library supports Backend.AI API v3 and above.

Install

$ npm install backend.ai-client

You can also use yarn.

$ yarn install backend.ai-client

Build

Package preparation

NPM:

$ npm i

Yarn:

$ yarn install

ES6+ library

$ make es6

Node.js library

$ make node 

Usage

TypeScript:

import * as ai from 'backend.ai-client-node';

let config = ai.backend.ClientConfig.createFromEnv();
let client = new ai.backend.Client(config);

CommonJS-style:

const ai = require('backend.ai-client-node');

let config = ai.backend.ClientConfig.createFromEnv();
let client = new ai.backend.Client(config);

ES6+:

import './backend.ai-client-es6.js';

let config = new ai.backend.ClientConfig(
  '[ADD_ACCESS_KEY_HERE]',
  '[ADD_SECRET_KEY_HERE]',
  '[ENDPOINT_HERE]'
);
let client = new ai.backend.Client(
  config,
  `Backend.AI ES6 App.`,
);

When creating ClientConfig object, you can manually pass accessKey,
secretKey, and optional endpoint arguments.
The environment variables are:

  • BACKEND_ACCESS_KEY
  • BACKEND_SECRET_KEY
  • BACKEND_ENDPOINT (optional, defaults to https://api.backend.ai)

All API functions return a promise that resolves into a parsed object
when success according to server-provided Content-Type and rejects with an
object with type and message attributes if failed.

client.createIfNotExists('python:latest', 'my-session-id')
.then(response => {
  console.log(`my session is created: ${response.kernelId}`);
}).catch(err => {
  switch (err.type) {
  case ai.backend.Client.ERR_SERVER:
    console.log(`session creation failed: ${err.message}`);
    break;
  default:
    console.log(`request/response failed: ${err.message}`);
  }
});

The result objects returned with success has different formats API by API.
Please check out our official documentation.

err.type is one of the following values:

  • ai.backend.Client.ERR_SERVER: The server responded with failure.
    In this case, err.message includes HTTP status and additional error information
    returned by the API server.
  • ai.backend.Client.ERR_RESPONSE: An error occurred while reading the response.
    err.message includes an exception value passed from your Javascript runtime.
  • ai.backend.Client.ERR_REQUEST: An error occurred while sending the request.
    err.message includes an exception value passed from your Javascript runtime.

Main metrics

Overview
Name With Ownerlablup/backend.ai-client-js
Primary LanguageJavaScript
Program languageJavaScript (Language Count: 3)
Platform
License:MIT License
所有者活动
Created At2017-09-01 00:49:40
Pushed At2023-04-19 02:19:07
Last Commit At2020-04-27 13:48:27
Release Count0
用户参与
Stargazers Count5
Watchers Count18
Fork Count4
Commits Count61
Has Issues Enabled
Issues Count10
Issue Open Count4
Pull Requests Count6
Pull Requests Open Count12
Pull Requests Close Count6
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private