Skip to content
hannsolo edited this page May 6, 2020 · 3 revisions

This documentation is intended to get you going with the FSI Server API javascript client and serves as a reference for the available methods and interfaces.

If you want to see this API client in action you can check out the web interface of the demo FSI Server.

Of course far more complex tasks can be accomplished using the API client in your own project.

Installation

Install with npm:

npm install @neptunelabs/fsi-server-api-client

Install with yarn:

yarn add @neptunelabs/fsi-server-api-client

Concepts

Promise based API versus queue API

There are two ways of using the API:

  • the promise based client API
  • the queue API

Queueing command results in a far more readable code while using the promise based API gives you more flexibility, but a heavily nested code.

Let's have a look at a simple example which just creates a session on FSI Server, reads a directory and closes the session:

Example A: Client API
const FSIServerClient = require("@neptunelabs/fsi-server-api-client").FSIServerClient;
const client = new FSIServerClient('https://my.fsi-server.tld');

client.login("user", "password")
  .then( () => {
    client.listServer("images/foo")
      .then ( (list) => {
        client.logout()
        .catch(console.error);  
    })
    .catch(console.error);
})
.catch(console.error);
Example B: Queue API
const FSIServerClient = require("@neptunelabs/fsi-server-api-client").FSIServerClient;
const client = new FSIServerClient('https://my.fsi-server.tld');
client.setLogLevel(FSIServerClient.LogLevel.info);

const queue = client.createQueue({continueOnError:false});
queue.login("user", "password");
queue.listServer("images/foo");
queue.logout();

// the following line actually starts the execution
queue.runWithResult();

Both examples do the exact same thing, but the nested promises example A) is way harder to read, especially if the tasks get more complex.
The index to the right, therefore, documents the "client API" as well as the "queue API" in separate sections.

Clone this wiki locally