tachybase_todo/docs/cores/packages/sdk.md
chenos d5d0e1036b
docs: add docs (#75)
* docs: add docs

* ignore dumi theme test

* fix: error TS2717: Subsequent property declarations must have the same type.

* update docs

* deploy gh-pages

* plugins docs

* hash & cname

* exportStatic

* ssr

* vercel

* vercel

* fix: deploy vercel

* Delete vercel.json

* docs

* fix APP_DIST

* on master branch
2021-04-17 21:33:21 +08:00

1.5 KiB
Raw Blame History

title order
@nocobase/sdk 3

@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,
});