Skip to main content

Overview

This Client API documentation will guide you how to use the key modules of the client library to integrate your Altogic backend apps with your frontends.

Key modules

There are several modules in our client library that you can use in your frontend applications.

  • Authentication - Handles the authentication process of your application users. Provides methods to manage users, sessions and authentication. You are free to design the way to authenticate your users and manage sessions in Altogic through defining your custom services. However, by default Altogic provides email, phone number and 3rd party oAuth provider based authentication to manage user accounts through the client library.
  • Database - Allows you manage your applications database. With the database module you can create new objects in your app database, update or delete existing ones, run queries and paginate over large data sets.
  • Cloud Storage - Provides the methods to manage your app's cloud storage buckets and files. With this module you store your files, documents, images etc. under buckets, which are the basic containers that hold your application data.
  • Cloud Functions - Enables you to run your business logic and processes in your Altogic backend. There are three types of cloud functions (aka services) that you can define in Altogic.
    • Endpoints - Provides the methods to execute your app backend services by making REST API requests to your app endpoints.
    • Message Queues - Allows different parts of your application to communicate and perform activities asynchronously. Message queue services are triggered when a message is submitted to a queue.
    • Scheduled Tasks - Enables you to manually trigger service executions of your scheduled tasks (aka cron jobs) which actually ran periodically at fixed times, dates, or intervals
  • Realtime - Allows realtime publish and subscribe (pub/sub) messaging through websockets.Realtime makes it possible to open a two-way interactive communication session between the user's device (e.g., browser, smartphone) and a server. With realtime, you can send messages to a server and receive event-driven responses without having to poll the server for a reply.
  • Cache - Provides simple key-value storage at a high-speed data storage layer (Redis) speeding up data set and get operations.

Response structure

Ignoring few exceptions (e.g., auth.getSession, auth.getUser), the client library method executions return a json object which includes two main components, the method response data and the errors.

Success response

If the client library method exeuction completes successfully then the returned json object's response data field(s) will be populated and the errors field will be set to null. The response data structure can be different for each method. Please refer to the specific method's documentation for the response data structure.

//Get user and session data using the accessToken
const result = await altogic.auth.getAuthGrant(accessToken);
Success response example
{
"user": {
"_id": "6235e0eb25de47092f4d5300",
"provider": "altogic",
"providerUserId": "6235e0eb25de47092f4d5300",
"email": "[email protected]",
"signUpAt": "2022-03-19T13:55:55.772Z",
"lastLoginAt": "2022-03-19T13:58:42.376Z",
"emailVerified": true,
"name": "Rooby"
},
"session": {
"userId": "6235e0eb25de47092f4d5300",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbnZJZCI6I...",
"userAgent": {
"family": "Chrome",
"major": "99",
"minor": "0",
"patch": "4844",
"device": {
"family": "Other",
"major": "0",
"minor": "0",
"patch": "0"
},
"os": {
"family": "Mac OS X",
"major": "10",
"minor": "15",
"patch": "7"
}
},
"accessGroupKeys": []
},
"errors": null
}

Error response

If the client library method exeuction has errors then the returned json object's response data will be null and the errors field will include the list of errors occurred.

//Get cloud storage file metadata
let result = await altogic.storage
.bucket("profile picture")
.file("profile1.png")
.getInfo();
Error response example
{
"data": null,
"errors": {
"status": 400,
"statusText": "Bad Request",
"items": [
{
"origin": "client_error",
"code": "bucket_not_found",
"message": "Cannot identify the bucket 'sdfsdf'"
}
]
}
}
note

You can check the returned json object's errors field value to identify failures. If the value of errors is null, this means that the method call completed successfully otherwise errors field will hold the list of errors occured.