GithubHelp home page GithubHelp logo

shyun-comcom / backend.ai-client-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lablup/backend.ai-client-js

0.0 1.0 0.0 88 KB

Backend.AI Client Library for Javascript

License: MIT License

JavaScript 100.00%

backend.ai-client-js's Introduction

Backend.AI Client for Javascript (ES6+)

Requirements

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

Install

$ npm install backend.ai-client

Usage

TypeScript:

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

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

CommonJS-style:

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

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

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.