界面:BackendV0

容器方法

execInContainer

execInContainer(container, cmd): Promise< ExecResultV0>

在容器内执行命令。

const output = await window.ddClient.backend.execInContainer(container, cmd);

console.log(output);

警告

此方法将在未来版本中移除。

参数

名称类型描述
container字符串-
cmd字符串要执行的命令。

返回

Promise< ExecResultV0>


HTTP 方法

get

get(url): Promise<unknown>

向后端服务执行 HTTP GET 请求。

window.ddClient.backend
 .get("/some/service")
 .then((value: any) => console.log(value));

警告

此方法将在未来版本中移除。请使用 get 代替。

参数

名称类型描述
url字符串后端服务的 URL。

返回

Promise<unknown>


post

post(url, data): Promise<unknown>

向后端服务执行 HTTP POST 请求。

window.ddClient.backend
 .post("/some/service", { ... })
 .then((value: any) => console.log(value));

警告

此方法将在未来版本中移除。请使用 post 代替。

参数

名称类型描述
url字符串后端服务的 URL。
data任意类型请求正文。

返回

Promise<unknown>


put

put(url, data): Promise<unknown>

向后端服务执行 HTTP PUT 请求。

window.ddClient.backend
 .put("/some/service", { ... })
 .then((value: any) => console.log(value));

警告

此方法将在未来版本中移除。请使用 put 代替。

参数

名称类型描述
url字符串后端服务的 URL。
data任意类型请求正文。

返回

Promise<unknown>


patch

patch(url, data): Promise<unknown>

向后端服务执行 HTTP PATCH 请求。

window.ddClient.backend
 .patch("/some/service", { ... })
 .then((value: any) => console.log(value));

警告

此方法将在未来版本中移除。请使用 patch 代替。

参数

名称类型描述
url字符串后端服务的 URL。
data任意类型请求正文。

返回

Promise<unknown>


delete

delete(url): Promise<unknown>

向后端服务执行 HTTP DELETE 请求。

window.ddClient.backend
 .delete("/some/service")
 .then((value: any) => console.log(value));

警告

此方法将在未来版本中移除。请使用 delete 代替。

参数

名称类型描述
url字符串后端服务的 URL。

返回

Promise<unknown>


head(url): Promise<unknown>

向后端服务执行 HTTP HEAD 请求。

window.ddClient.backend
 .head("/some/service")
 .then((value: any) => console.log(value));

警告

此方法将在未来版本中移除。请使用 head 代替。

参数

名称类型描述
url字符串后端服务的 URL。

返回

Promise<unknown>


request

request(config): Promise<unknown>

向后端服务执行 HTTP 请求。

window.ddClient.backend
 .request({ url: "/url", method: "GET", headers: { 'header-key': 'header-value' }, data: { ... }})
 .then((value: any) => console.log(value));

警告

此方法将在未来版本中移除。请使用 request 代替。

参数

名称类型描述
configRequestConfigV0后端服务的 URL。

返回

Promise<unknown>


虚拟机方法

execInVMExtension

execInVMExtension(cmd): Promise< ExecResultV0>

在后端容器内执行命令。如果您的扩展程序附带应在后端容器内运行的其他二进制文件,您可以使用execInVMExtension函数。

const output = await window.ddClient.backend.execInVMExtension(
  `cliShippedInTheVm xxx`
);

console.log(output);

警告

此方法将在未来版本中移除。请使用 exec 代替。

参数

名称类型描述
cmd字符串要执行的命令。

返回

Promise< ExecResultV0>


spawnInVMExtension

spawnInVMExtension(cmd, args, callback): void

返回在后端容器中执行的命令的流。

window.ddClient.spawnInVMExtension(
  `cmd`,
  [`arg1`, `arg2`],
  (data: any, err: any) => {
    console.log(data.stdout, data.stderr);
    // Once the command exits we get the status code
    if (data.code) {
      console.log(data.code);
    }
  }
);

警告

此方法将在未来版本中移除。

参数

名称类型描述
cmd字符串要执行的命令。
args字符串[]要执行的命令的参数。
callback(data: any, error: any) => void用于监听命令输出数据和错误的回调函数。

返回

void