UNPKG

@obelisk/client

Version:

Typescript client to interact with Obelisk on a higher level than the regular ReST API calls.

52 lines (37 loc) 2 kB
# Obelisk Client A client library written in Typescript to interact with [Obelisk](https://obelisk.ilabt.imec.be). ## Prerequisites This library makes use of **RxJS** (Reactive Extensions for JavaScript). RxJS comes as a peer dependency. ## Overview ** This client library only works for web applications that connect on behalf of users. It is meant for the browser, so node-js servers cannot use this. _(For those use cases, please refer to the HTTP ReST API documented on [Obelisk](https://obelisk.ilabt.imec.be))_** The client helps to make authorized calls to the API. With the client you create *Endpoints*. These endpoints can be acted on with methods like `execute()` or `get()`. An endpoint takes an API uri as argument. **This means that the [HTTP REST api](https://obelisk.ilabt.imec.be/api/v1/spec/swagger) is as important to you, as this API.** ## Installation ```bash npm install @obelisk/client rxjs --save ``` ## Usage To start you need to create an ObeliskClient instance with a proper options object. ```typescript import { ClientOptions, ObeliskClient } from '@obelisk/client'; const options: ClientOptions = { host: 'https://obelisk.ilabt.imec.be', apiVersion: 'v1', realm: 'idlab-iot', clientId: 'my-client' } let client = new ObeliskClient(options); ``` Now init the client to connect to the Obelisk back-end and start using it. init() returns an Observable that completes once initialization is over. ```typescript this.client.init().subscribe({ next: _ => { // do something with the client } }) ``` *If you are logged in it will handle all the tokens in the headers for you.* ## Angular There is an optional angular package to use in conjunction with the client packages. More information can be found at [@obelisk/ngx](https://www.npmjs.com/package/@obelisk/ngx). ## Client API The generated @obelisk/client api can be found [here](https://obelisk.ilabt.imec.be/api/v1/client-docs)