tachybase_todo/docs/cores/packages/sdk.md
2021-09-02 11:01:58 +08:00

1.5 KiB
Raw Blame History

title order
@nocobase/sdk 5

@nocobase/sdk 待完善

介绍

安装

yarn add @nocobase/sdk

Usage

SDK

import API from '@nocobase/sdk';

const api = new API({
  baseUrl: 'http://localhost:3000/api'
});

// 细节待补充
await api.resource('demos').list();
await api.resource('demos').create();
await api.resource('demos').get();
await api.resource('demos').update();
await api.resource('demos').destroy();

HTTP API

GET http://localhost:3000/api/demos
POST http://localhost:3000/api/demos
GET http://localhost:3000/api/demos/1
PUT http://localhost:3000/api/demos/1
DELETE http://localhost:3000/api/demos/1

API

# 独立资源
<requestMethod> /api/<resourceName>:<actionName>?<queryString>
<requestMethod> /api/<resourceName>:<actionName>/<resourceKey>?<queryString>

# 关系资源
<requestMethod> /api/<associatedName>/<associatedKey>/<resourceName>:<actionName>?<queryString>
<requestMethod> /api/<associatedName>/<associatedKey>/<resourceName>:<actionName>/<resourceKey>?<queryString>

<body> # 非 GET 请求时,可以提供 body 数据,一般为 JSON 格式

SDK

与 context.action.params 参数大体一致:

api.resource('<resourceName>').<actionName>({
  resourceKey,
  filter,
  fields,
  sort,
  page,
  perPage,
  values,
});

// 关系资源
api.resource('<associatedName>.<resourceName>').<actionName>({
  associatedKey,
  resourceKey,
  filter,
  fields,
  sort,
  page,
  perPage,
  values,
});