Rest
Rest — a class for making Rest API calls to the Аспро.Cloud platform. Singleton instance is available after Frame initialization.
Automatically manages authorization (OAuth2) and request rate limiting (RateLimiter).
import { Rest } from '@aspro-cloud/miniapp-jssdk'Properties
oauth2
OAuth2 instance for managing authorization tokens
get oauth2(): OAuth2rateLimiter
RateLimiter instance for request rate control
get rateLimiter(): RateLimiterMethods
getInstance
Returns the current singleton instance of Rest. Call only after Frame initialization
static getInstance(): Restcall
Universal Rest API call method, delegating execution to get() or post() depending on the request type
async call(params: RestCallParams): Promise<any>| Parameter | Type | Description |
|---|---|---|
params | RestCallParams | Request parameters |
destroy
Removes subscriptions and releases resources
destroy(): voidget
Performs a GET request to the Rest API for retrieving a single record or a list of records. When retrieving a list, it supports pagination, search, and filtering parameters
async get(method: string, params?: RestGetParams): Promise<any>| Parameter | Type | Description |
|---|---|---|
method | string | API method URL, e.g. '/core/user/list' |
params | RestGetParams | Request parameters: limit, page, search, fields, filter |
post
Performs a POST request to the Rest API for creating, updating, or deleting a record
async post(method: string, data?: RestPostData): Promise<any>| Parameter | Type | Description |
|---|---|---|
method | string | API method URL, e.g. '/core/user/update/39' |
data | RestPostData | Request data |
Example
import { App, Rest } from '@aspro-cloud/miniapp-jssdk'
await App.initializeFrame()
const rest = Rest.getInstance()
// Get list of users
const users = await rest.get('/core/user/list', {
limit: 50,
fields: ['id', 'name']
})
// Get current user
const user = await rest.get('/core/user/get/')
// Get user by id
const user39 = await rest.get('/core/user/get/39')
// Update user data
await rest.post('/core/user/update/39', {
email_personal: 'neo@aspro.cloud',
})
// Universal call
const result = await rest.call({
type: 'get',
method: '/core/user/list',
params: { limit: 10 }
})const App = window.ACloudMiniApp
const frame = await App.initializeFrame()
// Get list of users
const users = await frame.rest.get('/core/user/list', {
limit: 50,
fields: ['id', 'name']
});
// Get current user
const user = await frame.rest.get('/core/user/get/');
// Get user by id
const user39 = await frame.rest.get('/core/user/get/39');
// Update user data
await frame.rest.post('/core/user/update/39', {
email_personal: 'neo@aspro.cloud',
});
// Universal call
const result = await frame.rest.call({
type: 'get',
method: '/core/user/list',
params: { limit: 10 }
});Pagination, Search, and Filtering
When retrieving a list of records via get(), additional parameters are available:
| Field | Type | Description |
|---|---|---|
limit | number | Maximum number of records per request. Default is 50, maximum is 100 |
page | number | Page number of the request result. Default is 1 |
search | string | Search query |
fields | string[] | List of fields to return in the response |
filter | RestFilter | Array of parameters for filtering the list of records |
import { App, Rest } from '@aspro-cloud/miniapp-jssdk'
await App.initializeFrame()
const rest = Rest.getInstance()
// Limit the maximum number of records in the response to 100
const users = await rest.get('/core/user/list', {
limit: 100,
})
// Pagination - second page with 50 records per page (default)
const usersSecondPage = await rest.get('/core/user/list', {
page: 2,
})
// Limit the list of fields to return in the response
const usersCompact = await rest.get('/core/user/list', {
fields: ['id', 'name']
})
// Search by string
const usersBySearch = await rest.get('/core/user/list', {
search: 'neo',
})
// Filter by field value
const usersByUsername = await rest.get('/core/user/list', {
filter: {
username: 'neo@aspro.cloud',
},
})
// Filter by a list of values
const usersByIds = await rest.get('/core/user/list', {
filter: {
id: [39, 64],
},
})
// Filter with value exclusion
const usersByExcludedIds = await rest.get('/core/user/list', {
filter: {
id: ['!39', '!64'],
},
})
// Filter by time
const tasksByUpdatedDate = await rest.get('/task/task/list', {
filter: {
updated_date: '2025-03-26 10:50:34',
},
})
// Filter by time range
const tasksByDateRange = await rest.get('/task/task/list', {
filter: {
updated_date: {
start_date: '2025-01-01 00:00:00',
end_date: '2025-12-31 23:59:59',
},
},
})
// Filter with exact match
const tasksByExactId = await rest.get('/task/task/list', {
filter: {
id: {
type: 'exact_value',
value: 1550,
},
},
})
// Filter with maximum value
const tasksWithMaxId = await rest.get('/task/task/list', {
filter: {
id: {
type: 'less',
value: 50,
},
},
})
// Filter with minimum value
const tasksWithMinId = await rest.get('/task/task/list', {
filter: {
id: {
type: 'more',
value: 1550,
},
},
})
// Filter with value range
const tasksByIdRange = await rest.get('/task/task/list', {
filter: {
id: {
type: 'range',
start_value: 50,
end_value: 1550,
},
},
})