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}/search/{query} ApiController#search Search record by query string
.../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 174

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

ForbiddenError When user cannot perform given action. Action#isAccessible returns false

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 215

action response

Promise.<any>

# 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 243

action response

Promise.<any>

# async recordAction(request, 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
request ActionRequest
response any

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

ConfigurationError When given record action doesn't return RecordJSON

ForbiddenError When user cannot perform given action: Action#isAccessible returns false

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

action response

Promise.<RecordActionResponse>

# async resourceAction(request, 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
request ActionRequest
response object

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

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

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

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

found records

Promise.<SearchResponse>

Type Definitions

object

# SearchResponse

Response of a Search action in the API

Properties:
Name Type Description
records Array.<RecordJSON>

List of records

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