logologo
Get Started
Guide
Development
Plugins
API
Home
English
简体中文
日本語
한국어
Español
Português
Deutsch
Français
Русский
Italiano
Türkçe
Українська
Tiếng Việt
Bahasa Indonesia
ไทย
Polski
Nederlands
Čeština
العربية
עברית
हिन्दी
Svenska
Get Started
Guide
Development
Plugins
API
Home
logologo
RunJS Overview
Import Modules
Render in Container

Globals

window
document
navigator

ctx

ctx.blockModel
ctx.collection
ctx.collectionField
ctx.dataSource
ctx.dataSourceManager
ctx.element
ctx.exit()
ctx.exitAll()
ctx.filterManager
ctx.form
ctx.getModel()
ctx.getValue()
ctx.getVar()
ctx.i18n
ctx.importAsync()
ctx.initResource()
ctx.libs
ctx.location
ctx.logger
ctx.makeResource()
ctx.message
ctx.modal
ctx.model
ctx.notification
ctx.off()
ctx.on()
ctx.openView()
ctx.render()
ctx.request()
ctx.requireAsync()
ctx.resource
ctx.route
ctx.router
ctx.setValue()
ctx.sql
ctx.t()
ctx.view
Previous Pagectx.render()
Next Pagectx.requireAsync()

#ctx.request()

Send authenticated HTTP requests in RunJS. Requests automatically include the current app's baseURL, token, cookies, etc.

#Type definition

request(options: RequestOptions): Promise<any>

RequestOptions extends Axios AxiosRequestConfig:

type RequestOptions = AxiosRequestConfig & {
  skipNotify?: boolean | ((error: any) => boolean);  // skip global error notification on failure
  skipAuth?: boolean;                                  // skip auth redirect
};

#Notes

  • Requests include baseURL, token, cookies, and interceptors.
  • Supports same-origin requests (relative paths or same origin), and cross-origin requests (full URL, target must allow CORS).
  • Standard options (url, method, params, data, etc.) are supported. URLs can use resource style (e.g. users:list, posts:update).

#Common parameters (Axios style)

ParameterTypeDescription
urlstringRequest URL, can be resource style like users:list, posts:update
method'get' | 'post' | 'put' | 'patch' | 'delete'HTTP method, default 'get'
paramsobjectQuery params serialized into URL
dataanyRequest body for post/put/patch
headersobjectCustom headers
skipNotifyboolean | (error) => booleanWhen true or function returns true, skip global error message
skipAuthbooleanWhen true, request failure (e.g. 401) won't trigger auth redirect

#Examples

#List query

const { data } = await ctx.request({
  url: 'users:list',
  params: { pageSize: 10 },
});

#Submit data

const res = await ctx.request({
  url: 'users:create',
  method: 'post',
  data: { nickname: 'Alice', email: 'alice@example.com' },
});

#Filter and sort

const res = await ctx.request({
  url: 'users:list',
  method: 'get',
  params: {
    pageSize: 20,
    sort: ['-createdAt'],
    filter: { status: 'active' },
  },
});

#Skip error notification

const res = await ctx.request({
  url: 'some:action',
  method: 'get',
  skipNotify: true,  // skip global message on failure
});

#Cross-origin request

Use a full URL to call another domain. The target service must enable CORS.

const res = await ctx.request({
  url: 'https://api.example.com/v1/data',
  method: 'get',
});

// If the target API requires its own token, pass it via headers
const res2 = await ctx.request({
  url: 'https://api.other.com/items',
  method: 'get',
  headers: {
    Authorization: 'Bearer <target-service-token>',
  },
});