Bỏ qua, đến nội dung

@digiforce-nc/plugin-data-source-rest-api

Plugin kết nối REST API bên ngoài làm data source — biến các HTTP endpoint thành collection để thao tác dữ liệu từ giao diện Digiforce.

Plugin này làm gì?

Không phải dữ liệu nào cũng nằm trong database. Nhiều hệ thống cung cấp dữ liệu qua REST API (CRM, ERP, SaaS). Plugin này đăng ký loại data source rest-api vào data-source-manager factory, cho phép map HTTP endpoints thành collection — mỗi endpoint tương ứng một collection, mỗi JSON response field tương ứng một field.

Cơ chế hoạt động

Tính năng chính

#Tính năngMô tả
1Map endpoint → collectionMỗi REST endpoint trở thành một collection
2CRUD mappingMap GET/POST/PUT/DELETE sang list/create/update/destroy
3AuthenticationHỗ trợ API Key, Bearer Token, Basic Auth, OAuth2
4Field mappingMap JSON response fields thành collection fields
5PaginationHỗ trợ offset, cursor-based, page-based pagination
6Request transformTùy chỉnh headers, query params, body transform

Cấu hình kết nối

Tham sốBắt buộcMô tảVí dụ
baseUrlCoURL gốc của APIhttps://api.example.com/v1
authTypeKhôngKiểu xác thựcbearer, apiKey, basic
authTokenKhôngToken xác thựceyJhbGci...
headersKhôngHeaders mặc địnhContent-Type: application/json
timeoutKhôngTimeout request (ms)30000

Kiến trúc nội bộ

Thành phầnVai trò
RegisterĐăng ký rest-api type vào factory
ConfigLưu cấu hình endpoints (URL, method, params)
AdapterGọi HTTP request với auth, headers, transform
MapperChuyển JSON response thành collection records

Thành phần client

Thành phầnMô tả
RESTConfigFormForm cấu hình base URL và authentication
EndpointEditorGiao diện định nghĩa endpoint → collection mapping
FieldMapperMap JSON fields sang collection fields
RequestTesterGửi request thử và xem response

Dependencies

PackageVai trò
@digiforce-nc/serverServer framework
@digiforce-nc/clientClient UI framework
@digiforce-nc/data-source-managerRegistry quản lý data source
axiosHTTP client cho REST requests

Lưu ý triển khai

  • API bên ngoài cần accessible từ server Digiforce (firewall, VPN)
  • Rate limiting phụ thuộc vào API provider
  • Response phải là JSON format
  • Nên cache response cho API không thay đổi thường xuyên

Mục lục chi tiết