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
Field | Type | Required | Description |
---|---|---|---|
callContainerOptions | ICallContainerOptions<ParaT> | Yes | Cloud Hosting call request parameters |
opts | ICustomReqOpts | No | Custom configurations, currently supports setting the SDK request timeout, {timeout: number} |
ICallContainerOptions<ParaT>
Field | Type | Required | Description |
---|---|---|---|
name | string | Yes | Cloud Hosting service name |
method | string | No | HTTP request method |
path | string | No | HTTP request path |
header | Record<string, string> | No | HTTP request headers |
data | object | No | HTTP request body |
3. Response
Promise<CallContainerResult<ResultT>>
Field | Type | Required | Description |
---|---|---|---|
requestId | string | No | RequestId, used for error troubleshooting |
statusCode | number | No | HTTP response status code, used for error troubleshooting |
header | Record<string, string> | No | HTTP response headers, used for error troubleshooting |
data | ResultT | No | HTTP 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)
}