Installation
Pre-requisites
Altogic client library allows you to access the Altogic services from your web/mobile applications. In order to use the Altogic client library you need to create an app, deploy your app to an environment and a client key in Altogic. Optionally, you might also need to get your API Key which is used to manage access to your cloud functions.
info
When you create an app, Altogic creates an environment for you, deploys your app to this environment and creates a master client key that you can custimize later by default. You can access the all the required information (e.g., client key, base URL) to initialize the client library from the Home view of you app in Altogic Designer.
Creating an account in Altogic
To create an account in Altogic, you can visit the Designer which is the core visual development tool that you use to design, develop and deploy your backend applications.
Creating an app
You can create an app with the Designer. To create an app via the Designer:
- Log in to Altogic with your credentials.
- Select New app.
- In the App name field, enter a name for the app.
- In the Sub domain field, enter a sub-domain for the app.
- In the Execution environment region field, select a region for the app. This will be the location where your app's initial environment will be created.
- In the Execution environment pricing plan field, select available pricing plan for your environment.
- In starter templates section, select the Basic template
- Select Create.
- Click/tap on the newly created app to launch the app.

Creating client key
You can create a client key to control access to your app's services and define the access rights of each of the key modules of the client library. When you create a new application your client key will be automatically created for you.
You can create a new client key and manage existing ones using the Designer. To create a client key via the Designer:
- Launch the Designer.
- From your workspace, selec the application that you would like to manage its client keys.
- Click/tap on App Settings at the left-bottom of the designer.
- Click/tap on Client library keys section.
- Click/tap on New client key button.
- In the Client key name field, enter a client key name for the app.

- (Optional) In order to protect your application, Altogic can restrict the client library to make calls only from "Authorized Domains". In the Advanced section, by selecting Only authorized domains you can restrict domains of the client key.
- (Optional) Altogic can cap the client library RESTful API requests, namely the requests made from database, cache, storage, message queue and task modules in a specific timeframe. Altogic can also cap the number of realtime messages that can be sent in a specific timeframe. In the Rate limiting section, you can set the RESTful API and Realtime rate limiters.

Getting environment url
You can create a new environment or access existing app's envUrl from the Environments view in Altogic Designer.
There are two types of envUrl that you can use when creating your Altogic client; subdomain or base URL. You can send a request to Altogic services using any of the base URL or subdomain information. The subdomain information can be updated via the Environment view, but the default base URL information cannot be changed. If you want to access Altogic services using different libraries (E.g., http, fetcher, axios), we recommend you to use your base URL information. To get the envUrl via the Designer:
- Launch the Designer.
- Click/tap on Environments at the left-bottom of the designer.
- Click/tap name of the Environment
- Scroll down to API BASE URL section.
- Copy subdomain or environment url.

Creating an API key (Optional)
As an option, you might also need to get your apiKey
which is used to manage
access to your cloud functions. The access rights of your app endpoints are
managed through API keys in your environments. To create an API key via the
Designer:
- Launch the Designer.
- Click/tap on Environments at the left-bottom of the designer.
- Click/tap name of the Environment
- Click/tap on API Keys section.
- Create a new API Key by clicking on New API Key button.

info
The API key is different than the clientKey
used when creating an instance of
Altogic client library. clientKey
is primarily used to manage access rigths of
the client library whereas apiKey
is used to manage access to your app
endpoints.
The main reason why there are two different keys is that you can call your app cloud functions using any other http client (e.g., axios, fetch) using the API key and you are not restricted to use Altogic's client library. However, we strongly recommend using our client library which significantly eases app development and integration of your frontend to your Altogic backend.
Library Installation
Using package manager
You can install the Altogic client library with package managers like npm, Yarn or pub for dart:
- npm
- Yarn
- Dart
npm install altogic
If you're using a bundler (like webpack), you can
import the Altogic and create your Altogic client instance. The creation of
client library requires two required parameters; envUrl
and clientKey
. The
envUrl
is the base URL of the Altogic application environment where a snapshot
of the application is deployed and clientKey
is the client library key of your
app.
yarn add altogic
If you're using a bundler (like webpack), you can
import the Altogic and create your Altogic client instance. The creation of
client library requires two required parameters; envUrl
and clientKey
. The
envUrl
is the base URL of the Altogic application environment where a snapshot
of the application is deployed and clientKey
is the client library key of your
app.
flutter pub add altogic
Or only dart:
dart pub add altogic_dart
- Javascript
- Dart
import { createClient } from "altogic";
// Create a client for interacting with Altogic backend app
// You need to provide `envUrl` and `clientKey` as input parameters
// Optionally, you can provide `apiKey`, `signInRedirect` and `realtime` parameters
// in options. More details can be found in the Options section
let envUrl = "https://c1-na.altogic.com/e:6233230ba1c78fcb1ad5919a";
let clientKey = "f59c9ef3a53b40669c6a79a62593e153";
const altogic = createClient(envUrl, clientKey);
CDN
To install with a CDN (content delivery network) add the following script to import Altogic client library.
<script src="https://cdn.jsdelivr.net/npm/altogic"></script>
Then you can use it from a global altogic
variable:
<script>
const { createClient } = altogic;
//Create a client for interacting with Altogic backend app
//You need to provide `envUrl` and `clientKey` as input parameters
const client = createClient(
"https://c1-na.altogic.com/e:6233230ba1c88fcb1ad5919a",
"f59c9ef3a53b40669b6a79a62593e153"
);
</script>
import 'package:altogic/altogic.dart';
// Create a client for interacting with Altogic backend app
// You need to provide `envUrl` and `clientKey` as input parameters
// Optionally, you can provide `apiKey`, `signInRedirect` and `realtime` parameters
// in options. More details can be found in the Options section
final envUrl = "https://c1-na.altogic.com/e:6233230ba1c78fcb1ad5919a";
final clientKey = "f59c9ef3a53b40669c6a79a62593e153";
final altogic = createClient(envUrl, clientKey);
Initialization options
You can initialize the client library with apiKey
, signInRedirect
, and
localStorage
options.
- Javascript
- Dart
import { createClient } from "altogic";
// Create a client for interacting with Altogic backend app
// You need to provide `envUrl` and `clientKey` as input parameters
// Optionally, you can also provide `apiKey`, `signInRedirect` and `realtime` options
let options = {
apiKey: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbnZJZCI6IjYyYzE0MDQ5...',
signInRedirect: 'http://localhost:3000/auth-redirect',
realtime: {
autoJoinChannels: false,
bufferMessages: true,
echoMessages: true,
reconnectionDelay: 2000,
timeout: 30000
}
}
const altogic = createClient(envUrl, clientKey, options);
info
By default Altogic client library uses Window.localStorage of the browser.
- If you prefer to use a different storage handler besides Window.localStorage or if you are using the Altogic client library at the server (not browser) then you need to provide your storage implementation.
import 'package:altogic/altogic.dart';
// Create a client for interacting with Altogic backend app
// You need to provide `envUrl` and `clientKey` as input parameters
// Optionally, you can also provide `apiKey`, `signInRedirect` and `realtime` options
final options = ClientOptions(
apiKey: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbnZJZCI6IjYyYzE0MDQ5...',
signInRedirect: (context) {
// do something
},
realtime: RealtimeOptions(
autoJoinChannels: false,
bufferMessages: true,
echoMessages: true,
reconnectionDelay: 2000,
timeout: 30000
)
);
final altogic = createClient(envUrl, clientKey, options);
info
By default altogic package uses shared_preferences package.
- If you prefer to use a different storage handler besides
shared_preferences then you need to provide your
ClientStorage
implementation.
Parameters
Here you can find parameters for the createClient
method.
# | Name | Data type | Required | Description |
---|---|---|---|---|
1 | envUrl | String | Yes | The base URL of the Altogic application environment where a snapshot of the application is deployed. |
2 | clientKey | String | Yes | The client library key of the app |
3 | options | ClientOptions | No | Additional client library options. |
Client Options
Here you can find properties for the ClientOptions
- Javascript
- Dart
# | Name | Data type | Required | Description |
---|---|---|---|---|
1 | apiKey | String | No | The unique app environment API Key which needs to be created using the Designer. The apiKey is passed in Authorization Header when making RESTful API calls to your app endpoints. This key is different than the clientKey used when creating an instance of Altogic client library. clientKey is primarily used to manage access rigths of the client library whereas apiKey is used to manage access to your app endpoints. |
2 | localStorage | ClientStorage | No | If you prefer to use a different storage handler besides Window.localStorage you need to define localStorage option. You need to define an object having following methods, 1. setItem(key:string, data:object) 2. getItem(key:string) 3. removeItem(key:string) |
3 | signInRedirect | String | No | The sign in page URL to redirect the user when user's session becomes invalid. Altogic client library observes the responses of the requests made to your app backend. If it detects a response with an error code of missing or invalid session token, it can redirect the users to this sign in URL. |
4 | realtime | RealtimeOptions | No | The configuration parameters for websocket connections. |
# | Name | Data type | Required | Description |
---|---|---|---|---|
1 | apiKey | String | No | The unique app environment API Key which needs to be created using the Designer. The apiKey is passed in Authorization Header when making RESTful API calls to your app endpoints. This key is different than the clientKey used when creating an instance of Altogic client library. clientKey is primarily used to manage access rigths of the client library whereas apiKey is used to manage access to your app endpoints. |
2 | localStorage | ClientStorage | No | If you prefer to use a different storage handler besides Window.localStorage you need to define localStorage option. You need to define an object having following methods, 1. setItem(key:string, data:object) 2. getItem(key:string) 3. removeItem(key:string) |
3 | signInRedirect | void Function(BuildContext? context) | No | The sign in page URL to redirect the user when user's session becomes invalid. Altogic client library observes the responses of the requests made to your app backend. If it detects a response with an error code of missing or invalid session token, it can call the callback. |
4 | realtime | RealtimeOptions | No | The configuration parameters for websocket connections. |
Realtime Options
Here you can find properties for the RealtimeOptions
# | Name | Data type | Required | Description |
---|---|---|---|---|
1 | autoJoinChannels | Boolean | No | The flag to enable or prevent automatic join to channels already subscribed in case of websocket reconnection. When websocket is disconnected, it automatically leaves subscribed channels. This parameter helps re-joining to already joined channels when the connection is restored. By default true . |
2 | bufferMessages | Boolean | No | By default, any event emitted while the realtime socket is not connected will be buffered until reconnection. You can turn on/off the message buffering using this parameter. |
3 | echoMessages | Boolean | No | The flag to enable or prevent realtime messages originating from this connection being echoed back on the same connection. By default true . |
4 | reconnectionDelay | Integer | No | The initial delay before realtime reconnection in milliseconds. By default 1000 milliseconds. |
5 | timeout | Integer | No | The timeout in milliseconds for each realtime connection attempt. By default 20000 milliseconds. |