ctx.request()
Initiate an authenticated HTTP request within RunJS. The request automatically carries the current application's baseURL, Token, locale, role, etc., and follows the application's request interception and error handling logic.
Use Cases
Applicable to any scenario in RunJS where a remote HTTP request needs to be initiated, such as JSBlock, JSField, JSItem, JSColumn, Workflow, Linkage, JSAction, etc.
Type Definition
RequestOptions extends Axios's AxiosRequestConfig:
Common Parameters
Resource Style URL
NocoBase Resource API supports a shorthand resource:action format:
Relative paths will be concatenated with the application's baseURL (usually /api); cross-origin requests must use a full URL, and the target service must be configured with CORS.
Response Structure
The return value is an Axios response object. Common fields include:
response.data: Response body- List interfaces usually return
data.data(array of records) +data.meta(pagination, etc.) - Single record/create/update interfaces usually return the record in
data.data
Examples
List Query
Submit Data
With Filtering and Sorting
Skip Error Notification
Cross-Origin Request
When using a full URL to request other domains, the target service must be configured with CORS to allow the current application's origin. If the target interface requires its own token, it can be passed via headers:
Displaying with ctx.render
Notes
- Error Handling: Request failure will throw an exception, and a global error prompt will pop up by default. Use
skipNotify: trueto catch and handle it yourself. - Authentication: Same-origin requests will automatically carry the current user's Token, locale, and role; cross-origin requests require the target to support CORS and pass the token in headers as needed.
- Resource Permissions: Requests are subject to ACL constraints and can only access resources the current user has permission for.
Related
- ctx.message - Display lightweight prompts after the request is completed
- ctx.notification - Display notifications after the request is completed
- ctx.render - Render request results to the interface
- ctx.makeResource - Construct a resource object for chained data loading (alternative to
ctx.request)

