跳到主要内容

云托管

callContainer

1. 接口描述

接口功能:调用云托管服务

接口声明:callContainer<ParaT, ResultT>(callContainerOptions: ICallContainerOptions<ParaT>, opts?: ICustomReqOpts): Promise<CallContainerResult<ResultT>>

2. 输入参数

字段类型必填说明
callContainerOptionsICallContainerOptions<ParaT>云托管调用请求参数
optsICustomReqOpts自定义配置,目前支持 SDK 请求超时时间设置,{timeout: number}

ICallContainerOptions<ParaT>

字段类型必填说明
namestring云托管服务名
methodstringHTTP 请求方法
pathstringHTTP 请求路径
headerRecord<string, string>HTTP 请求头
dataobjectHTTP 请求体

3. 返回结果

Promise<CallContainerResult<ResultT>>

字段类型必填说明
requestIdstringRequestId,用于错误排查
statusCodenumberHTTP响应状态码,用于错误排查
headerRecord<string, string>HTTP响应头,用于错误排查
dataResultTHTTP响应体数据

函数执行报错,将通过异常抛出

4. 示例代码

import tcb from '@cloudbase/node-sdk'

exports.main = async (event, context) => {
const { httpContext } = context
const { url, httpMethod } = httpContext
console.log(`[${httpMethod}][${url}]`)

const tcbapp = tcb.init({ context })
const result = await tcbapp.callContainer({
name: 'helloworld',
method: 'POST',
path: '/abc',
data: {
key1: 'test value 1',
key2: 'test value 2'
},
{
timeout: 5000
}
})
console.log(result)
}