REST API data source

Introduction

Use this data source to connect data provided by REST APIs.

Installation

This is a commercial plugin. For activation instructions, see the Commercial plugin activation guide.

Add a REST API source

After activating the plugin, choose REST API from the Add new menu in Data source management.

Choose the REST API data source

Configure the REST API source.

Configure the REST API source

Add a collection

A RESTful resource maps to a NocoBase collection. For example, consider a Users resource:

GET /users
POST /users
GET /users/1
PUT /users/1
DELETE /users/1

It maps to the following NocoBase API configuration:

GET /users:list
POST /users:create
POST /users:get?filterByTk=1
POST /users:update?filterByTk=1
POST /users:destroy?filterByTk=1

For the complete NocoBase API design specification, see the API documentation.

API documentation entry

See the NocoBase API - Core section.

NocoBase API - Core

The REST API data-source collection is configured as follows.

List

Configure the API mapping for retrieving a resource list.

Configure the List API

Get

Configure the API mapping for retrieving resource details.

Configure the Get API

Create

Configure the API mapping for creating a resource.

Configure the Create API

Update

Configure the API mapping for updating a resource.

Configure the Update API

Destroy

Configure the API mapping for deleting a resource.

Configure the Destroy API

List and Get are required API mappings.

Debug APIs

Request parameter integration

For example, configure pagination parameters for the List API. If the third-party API itself does not support pagination, NocoBase paginates the returned list data.

Configure List pagination parameters

Only variables added to the API take effect.

Third-party API parameterNocoBase parameter
page{{request.params.page}}
limit{{request.params.pageSize}}

Click Try it out to debug the API and inspect the response.

Debug an API request

Response format conversion

The response format of a third-party API might not match the NocoBase standard. Convert it before it can be displayed correctly in the client.

Configure response conversion

Adjust the conversion rules according to the third-party API response so that it matches the NocoBase output standard.

Response conversion rules

Debugging flow.

Response conversion debugging flow

Error information conversion

When a third-party API returns an error, its error response might not match the NocoBase standard. Convert it before the client can display it correctly.

Configure error conversion

When error conversion is not configured, the error is converted by default to an error message that includes the HTTP status code.

Default error conversion

After configuring error conversion to match the NocoBase output standard, the client can display third-party API error information correctly.

Error conversion rules Converted third-party API error

Variables

The REST API data source provides three variable categories for API integration:

  • Data-source custom variables
  • NocoBase requests
  • Third-party responses

Data-source custom variables

Data-source custom variables

Configure a data-source custom variable

NocoBase requests

  • Params: URL query parameters (Search Params). The available Params differ between APIs
  • Headers: request headers, primarily providing NocoBase custom X- information
  • Body: the request body
  • Token: the API token of the current NocoBase request

NocoBase request variables

Third-party responses

Currently, only the response Body is available.

Third-party response variables

The available variables for each API integration are as follows.

List

ParameterDescription
request.params.pageCurrent page number
request.params.pageSizeNumber of records per page
request.params.filterFilter conditions. They must use the NocoBase Filter format.
request.params.sortSorting rules. They must use the NocoBase Sort format.
request.params.appendsFields loaded on demand, typically for loading relationship fields on demand
request.params.fieldsFields that the API returns, as an allowlist
request.params.exceptFields to exclude, as a denylist

Get

ParameterDescription
request.params.filterByTkRequired. Usually the ID of the current record
request.params.filterFilter conditions. They must use the NocoBase Filter format.
request.params.appendsFields loaded on demand, typically for loading relationship fields on demand
request.params.fieldsFields that the API returns, as an allowlist
request.params.exceptFields to exclude, as a denylist

Create

ParameterDescription
request.params.whiteListAllowlist
request.params.blacklistDenylist
request.bodyInitial data for creating the record

Update

ParameterDescription
request.params.filterByTkRequired. Usually the ID of the current record
request.params.filterFilter conditions. They must use the NocoBase Filter format.
request.params.whiteListAllowlist
request.params.blacklistDenylist
request.bodyData to update

Destroy

ParameterDescription
request.params.filterByTkRequired. Usually the ID of the current record
request.params.filterFilter conditions. They must use the NocoBase Filter format.

Configure fields

Extract field metadata (Fields) from data returned by the adapted resource CRUD APIs and use it as the fields of the collection.

Extract collection fields

Extract field metadata.

Extract field metadata

Fields and preview.

Fields and preview

Edit fields in the same way as for other data sources.

Edit REST API fields

Add REST API data-source blocks

After configuring the collection, you can add blocks to pages.

Add a REST API data-source block