Getting started
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 or websocket transports.
Initialization
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.
const apiClient = new client();
Setting custom URLs
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
> as follows:
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
> as follows:
const apiClient = client();
apiClient.url = {
http: new URL('https://api.deepaffex.cn:9443'),
wss: new URL('wss://api.deepaffex.cn:9080')
}
Session
The library keeps an internal session <ISession
> 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:
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:
const apiClient = client();
apiClient.session = { deviceToken: 'your-device-token', userToken: 'your-user-token' };