Class

ApiController

ApiController

Controller responsible for the auto-generated API: /admin_root/api/..., where admin_root is the rootPath given in AdminBroOptions.

The best way to utilise it is to use ApiClient on the frontend.

Available API endpoints

Endpoint Method Description
.../api/resources/{resourceId}/actions/{action} ApiController#resourceAction Perform customized resource action
.../api/resources/{resourceId}/records/{recordId}/{action} ApiController#recordAction Perform customized record action
.../api/resources/{resourceId}/bulk/{action}?recordIds={recordIds} ApiController#bulkAction Perform customized bulk action
.../api/pages/{pageName}_ ApiController#page Perform customized page action
.../api/dashboard_ ApiController#dashboard Perform customized dashboard action

Responsibility

In general this controllers takes handler functions you define in AdminBroOptions and:

You probably don't want to modify it, but you can call its methods by using ApiClient

Methods

# async bulkAction(request, response) → {Promise.<BulkActionResponse>}

Performs a customized bulk action. To call it use ApiClient#bulkAction method.

Handler function responsible for a .../api/resources/{resourceId}/bulk/{action}?recordIds={recordIds}

Parameters:
Name Type Description
request ActionRequest
response any

View Source admin-bro/src/backend/controllers/api-controller.ts, line 156

NotFoundError when recordIds are missing in query or they don't exists in the database

ConfigurationError when action handler doesn't return Promise<BulkActionResponse>

action response

Promise.<BulkActionResponse>

# async dashboard(request, response) → {Promise.<any>}

Gets optional data needed by the dashboard. To call it use ApiClient#getDashboard method.

Handler function responsible for a .../api/dashboard

Parameters:
Name Type Description
request ActionRequest
response any

View Source admin-bro/src/backend/controllers/api-controller.ts, line 190

action response

Promise.<any>

# async private getActionContext(request) → {Promise.<ActionContext>}

Returns context for given action

Parameters:
Name Type Description
request ActionRequest

request object

View Source admin-bro/src/backend/controllers/api-controller.ts, line 58

action context

Promise.<ActionContext>

# async page(request, response) → {Promise.<any>}

Gets optional data needed by the page. To call it use ApiClient#getPage method.

Handler function responsible for a .../api/pages/{pageName}

Parameters:
Name Type Description
request ActionRequest
response any

View Source admin-bro/src/backend/controllers/api-controller.ts, line 218

action response

Promise.<any>

# async recordAction(originalRequest, response) → {Promise.<RecordActionResponse>}

Performs a customized record action. To call it use ApiClient#recordAction method.

Handler function responsible for a .../api/resources/{resourceId}/records/{recordId}/{action}

Parameters:
Name Type Description
originalRequest ActionRequest
response any

View Source admin-bro/src/backend/controllers/api-controller.ts, line 120

ConfigurationError When given record action doesn't return RecordJSON

ConfigurationError when action handler doesn't return Promise<RecordActionResponse>

action response

Promise.<RecordActionResponse>

# async resourceAction(originalRequest, response) → {Promise.<ActionResponse>}

Performs a customized resource action. To call it use ApiClient#resourceAction method.

Handler function responsible for a .../api/resources/{resourceId}/actions/{action}

Parameters:
Name Type Description
originalRequest ActionRequest
response any

object from the plugin (i.e. admin-bro-expressjs)

View Source admin-bro/src/backend/controllers/api-controller.ts, line 102

action response

Promise.<ActionResponse>

Search records by query string.

Handler function responsible for a .../api/resources/{resourceId}/search/{query} route

Parameters:
Name Type Description
request ActionRequest

with params.query set

response any

View Source admin-bro/src/backend/controllers/api-controller.ts, line 82

found records

Promise.<SearchActionResponse>