Cloud Function
callFunction
1. Interface Description
Function: Execute cloud function
Interface declaration: callFunction(object: Object): Promise<Object>
2. Input Parameters
Field | Type | Required | Description |
---|---|---|---|
name | string | Yes | Cloud function name |
data | object | No | Cloud function parameters |
callback | function | No | Callback function |
parse | boolean | No | When set to true, if the function returns an object, the API will return the parsed object instead of a JSON string. This is applicable for directly viewing the returned results during browser debugging. |
Function Cloud Hosting can additionally pass parameters. After passing the type:'cloudrun'
parameter, the Function Cloud Hosting service will be invoked.
Field | Type | Required | Description |
---|---|---|---|
type | cloudrun | No | Whether to invoke the function-based cloud hosting service |
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. Output Parameters
Field | Type | Required | Description |
---|---|---|---|
code | string | No | Status code, not returned if the operation is successful |
message | string | No | Error description |
result | object | No | Cloud function execution result |
requestId | string | No | Request ID, used for error troubleshooting |
4. Sample Code
import cloudbase from "@cloudbase/js-sdk";
//Initialize the SDK instance
const app = cloudbase.init({
env: "xxxx-yyy",
});
app
.callFunction({
name: "test",
data: { a: 1 },
})
.then((res) => {
const result = res.result; // Cloud function execution result
});
Function Cloud Hosting Sample Code:
import cloudbase from "@cloudbase/js-sdk";
//Initialize the SDK instance
const app = cloudbase.init({
env: "xxxx-yyy",
});
app
.callFunction({
name: "test",
// Function Cloud Hosting parameters
type: "cloudrun",
method: "POST",
path: "/abc",
data: {
key1: "test value 1",
key2: "test value 2",
},
})
.then((res) => {
const result = res.result; // Cloud function execution result
});