Skip to main content

Cloud Hosting

callContainer

1. Interface Description

Function: Invoke Cloud Hosting services

Interface declaration: callContainer<ParaT, ResultT>(callContainerOptions: ICallContainerOptions<ParaT>, opts?: ICustomReqOpts): Promise<CallContainerResult<ResultT>>

2. Input Parameters

FieldTypeRequiredDescription
callContainerOptionsICallContainerOptions<ParaT>YesCloud Hosting call request parameters
optsICustomReqOptsNoCustom configurations, currently supports setting the SDK request timeout, {timeout: number}

ICallContainerOptions<ParaT>

FieldTypeRequiredDescription
namestringYesCloud Hosting service name
methodstringNoHTTP request method
pathstringNoHTTP request path
headerRecord<string, string>NoHTTP request headers
dataobjectNoHTTP request body

3. Response

Promise<CallContainerResult<ResultT>>

FieldTypeRequiredDescription
requestIdstringNoRequestId, used for error troubleshooting
statusCodenumberNoHTTP response status code, used for error troubleshooting
headerRecord<string, string>NoHTTP response headers, used for error troubleshooting
dataResultTNoHTTP response body data

Function execution errors will throw exceptions

4. Sample Code

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)
}