Skip to content

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).

ts
import { Rest } from '@aspro-cloud/miniapp-jssdk'

Properties

oauth2

OAuth2 instance for managing authorization tokens

ts
get oauth2(): OAuth2

rateLimiter

RateLimiter instance for request rate control

ts
get rateLimiter(): RateLimiter

Methods

getInstance

Returns the current singleton instance of Rest. Call only after Frame initialization

ts
static getInstance(): Rest

call

Universal Rest API call method, delegating execution to get() or post() depending on the request type

ts
async call(params: RestCallParams): Promise<any>
ParameterTypeDescription
paramsRestCallParamsRequest parameters

destroy

Removes subscriptions and releases resources

ts
destroy(): void

get

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

ts
async get(method: string, params?: RestGetParams): Promise<any>
ParameterTypeDescription
methodstringAPI method URL, e.g. '/core/user/list'
paramsRestGetParamsRequest parameters: limit, page, search, fields, filter

post

Performs a POST request to the Rest API for creating, updating, or deleting a record

ts
async post(method: string, data?: RestPostData): Promise<any>
ParameterTypeDescription
methodstringAPI method URL, e.g. '/core/user/update/39'
dataRestPostDataRequest data

Example

ts
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 }
})
js
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:

FieldTypeDescription
limitnumberMaximum number of records per request. Default is 50, maximum is 100
pagenumberPage number of the request result. Default is 1
searchstringSearch query
fieldsstring[]List of fields to return in the response
filterRestFilterArray of parameters for filtering the list of records
ts
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,
    },
  },
})

Published under the MIT license.