# SETL API SDK

The SETL API Node library provides convenient access to the SETL API from
applications written in server-side JavaScript.

## Documentation

See the [`SETL Labs` API docs](https://setl.io/labs/api) for more information (sign-up required).

## Installation

Install the package with:

```sh
npm install @setl/api-sdk --save
# or
yarn add @setl/api-sdk
```

## Usage

The package needs to be configured with your SETL Labs's address which is
available in your [SETL Labs Dashboard](https://setl.io/login).

```js
const { connect } = require('@setl/api-sdk');
const client = connect('example.setllabs.io');

const token = await client.login({
  username: 'username',
  password: 'password'
});

console.log(token);
```

Or using ES modules and `async`/`await`:

```js
import { connect } from '@setl/api-sdk';
const client = connect('example.setllabs.io');

(async () => {
  const token = await client.login({
    username: 'username',
    password: 'password'
  });

  console.log(token);
})();
```

### Usage with TypeScript

Import SetlApiSDK as a named import and instantiate it as `new SetlApiSDK(endpoint, options)` with the latest API version.

```ts
import { connect } from '@setl/api-sdk';
const client = connect('example.setllabs.io');

const getToken = async () => {
  const token = await client.login({
    username: 'username',
    password: 'password'
  });

  console.log(token);
};
getToken();
```

You can find a full TS server example in [SETL API SDK Examples](https://setl.io/login).