@nuralogix.ai/dfx-api-client
Version:
DeepAffex API JavaScript Client Library
79 lines (56 loc) • 2.48 kB
Markdown
This section will show you how to initialize and configure the library as well as working with the internal [session](
Once you configured the library, you can call endpoints using either [http](../API/http/index.md) or [websocket](../API/websocket/index.md) transports.
```js
import client from '@nuralogix.ai/dfx-api-client';
const apiClient = client();
```
Though not necessary, you can also use the `new` keyword when initializing the client, if you like.
```js
const apiClient = new client();
```
By default, the `http` and `WebSocket` URLs are pre-configured as follows and there is no need to set them.
```
http: https://api.deepaffex.ai:9443
wss: wss://api.deepaffex.ai:9080
```
If you want to use a custom URL when you initialize the client
then you can pass a URL object <[`IUrl`](../API/interfaces/IUrl.md)\> as follows:
```js
const apiClient = client({
url: {
http: new URL('https://api.deepaffex.cn:9443'),
wss: new URL('wss://api.deepaffex.cn:9080')
}
});
```
If you want to use a custom URL after you initialized the client
then you can pass a URL object <[`IUrl`](../API/interfaces/IUrl.md)\> as follows:
```js
const apiClient = client();
apiClient.url = {
http: new URL('https://api.deepaffex.cn:9443'),
wss: new URL('wss://api.deepaffex.cn:9080')
}
```
The library keeps an internal session <[`ISession`](../API/interfaces/ISession.md)\> object and populates/clears some
properties when different endpoints are called.
For example when `http.organizations.registerLicense` method is called
then the `deviceToken` and `deviceRefreshToken` are set
or when `http.users.login` is called then `userToken` and `userRefreshToken` are set.
If you want to manually set any of these properties, then you can do as follow:
```js
const apiClient = client();
apiClient.session = { deviceToken: 'your-device-token'};
```
and the library will only update that single property keeping the other properties previously set intact.
You can also set multiple properties all at once. This is useful when you already
have this information stored in another location such as `localStorage` and want to load
them without making network calls:
```js
const apiClient = client();
apiClient.session = { deviceToken: 'your-device-token', userToken: 'your-user-token' };
```