跳到主要内容

APIs

APIs 提供了一种灵活的方式来调用 V2 版本的 APIs 连接器。V2 版本的 APIs 创建方式请参考说明文档

提示

v3 版本在调用通用 APIs 时,使用的是 HTTP API 的开放能力。


APIs 使用参考

interface apis {
[apisLabel: string]: {
[
method: "request" | "post" | "get" | "head" | "patch" | "delete" | "put"
]: (
callApiOptions: ICallApiOptions,
opts?: IRequestOptions
) => Promise<ResponseObject["data"]>;
};
}

APIs 模块支持以下 HTTP 方法:

方法名描述示例
getGET 请求apis["apisLabel"].get(callApiOptions)
postPOST 请求apis["apisLabel"].post(callApiOptions)
putPUT 请求apis["apisLabel"].put(callApiOptions)
deleteDELETE 请求apis["apisLabel"].delete(callApiOptions)
headHEAD 请求apis["apisLabel"].head(callApiOptions)
patchPATCH 请求apis["apisLabel"].patch(callApiOptions)
request自定义方法请求apis["apisLabel"].request(callApiOptions)
提示

apisLabel 是 APIs 标识,在创建 V2 版本的 APIs 连接器时生成,可以在连接器的基本信息中查看

参数

callApiOptions
ICallApiOptions
opts
IRequestOptions

请求对象参数,一般不用传入,包含url、method、headers、body,作为定制化需求的补充,会覆盖 callApiOptions 中的同名参数

返回

res
ResponseObject['data']

HTTP 接口返回的 data 内容

示例

import cloudbase from "@cloudbase/js-sdk";

// 初始化 CloudBase 应用
const app = cloudbase.init({
env: "your-env-id", // 替换为您的环境ID
region: "ap-shanghai", // 地域,默认为上海
accessKey: "", // 填入生成的 Publishable Key,
});

// 获取 apis 实例
const apis = app.apis;