logologo
Get Started
Guide
Development
Plugins
API
English
简体中文
Get Started
Guide
Development
Plugins
API
English
简体中文
logologo
API Overview

@nocobase/auth

AuthManager
Auth
BaseAuth

@nocobase/cli

NocoBase CLI
Global Environment Variables

@nocobase/client

Application
Plugin

@nocobase/database

Collection
Field

interfaces

BaseInterface
Filter Operators

RelationRepository

BelongsToManyRepository
belongs-to-repository
HasManyRepository
HasOneRepository
Repository

shared

create-options
destroy-options
find-one
find-options
transaction
update-options

@nocobase/flow-engine

DataSourceManager
FlowContext
FlowEngine
FlowModel
FlowResource

@nocobase/server

AppCommand
Application
AuditManager
Context
Migration
Plugin

@nocobase/sdk

Auth
Storage
Previous PagePlugin
Next PageAuth

#APIClient

#Overview

APIClient is a wrapper based on axios, used to request NocoBase resource actions on the client side via HTTP.

#Basic Usage

class PluginSampleAPIClient extends Plugin {
  async load() {
    const res = await this.app.apiClient.request({
      // ...
    });
  }
}

#Instance Properties

#axios

The axios instance, which can be used to access the axios API, for example, apiClient.axios.interceptors.

#auth

Client-side authentication class, see Auth.

#storage

Client-side storage class, see Storage.

#Class Methods

#constructor()

Constructor, creates an APIClient instance.

#Signature

  • constructor(instance?: APIClientOptions)

#Type

interface ExtendedOptions {
  authClass?: any;
  storageClass?: any;
}

export type APIClientOptions =
  | AxiosInstance
  | (AxiosRequestConfig & ExtendedOptions);

#request()

Initiates an HTTP request.

#Signature

  • request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D> | ResourceActionOptions): Promise<R>

#Type

type ResourceActionOptions<P = any> = {
  resource?: string;
  resourceOf?: any;
  action?: string;
  params?: P;
};

#Details

#AxiosRequestConfig

General axios request parameters. See Request Config.

const res = await apiClient.request({ url: '' });
#ResourceActionOptions

NocoBase resource action request parameters.

const res = await apiClient.request({
  resource: 'users',
  action: 'list',
  params: {
    pageSize: 10,
  },
});
PropertyTypeDescription
resourcestring1. Resource name, e.g., a
2. Name of the resource's associated object, e.g., a.b
resourceOfanyWhen resource is the name of the resource's associated object, it is the primary key value of the resource. For example, for a.b, it represents the primary key value of a.
actionstringAction name
paramsanyRequest parameter object, mainly URL parameters. The request body is placed in params.values.
params.valuesanyRequest body object

#resource()

Gets the NocoBase resource action method object.

const resource = apiClient.resource('users');

await resource.create({
  values: {
    username: 'admin',
  },
});

const res = await resource.list({
  page: 2,
  pageSize: 20,
});

#Signature

  • resource(name: string, of?: any, headers?: AxiosRequestHeaders): IResource

#Type

export interface ActionParams {
  filterByTk?: any;
  [key: string]: any;
}

type ResourceAction = (params?: ActionParams) => Promise<any>;

export type IResource = {
  [key: string]: ResourceAction;
};

#Details

ParameterTypeDescription
namestring1. Resource name, e.g., a
2. Name of the resource's associated object, e.g., a.b
ofanyWhen name is the name of the resource's associated object, it is the primary key value of the resource. For example, for a.b, it represents the primary key value of a.
headersAxiosRequestHeadersHTTP headers to include in subsequent resource action requests.