How to Invoke a Cloud Function
Cloud Development provides multiple SDKs for developers to invoke cloud functions, including Mini Program SDK, Web SDK, Node.js SDK, HTTP API, etc.
Invocation Example
- Mini Program
- Web SDK
- Node.js SDK
- HTTP API
For details, please refer to: Mini Program: Invoking Cloud functions
const res = await wx.cloud.callFunction({
name: name: 'functionName', // cloud function name
data: {
// parameters passed to the cloud function
param1: 'value1',
param2: 'value2'
}
});
For details, please refer to: Web SDK
import cloudbase from "@cloudbase/js-sdk";
// Initialize the SDK instance
const app = cloudbase.init({
env: "your-env-id",
});
const res = await app.callFunction({
name: name: 'functionName', // cloud function name
data: {
// parameters passed to the cloud function
param1: 'value1',
param2: 'value2'
}
});
For details, please refer to: Node.js SDK
import cloudbase from "@cloudbase/node-sdk";
// Initialize the SDK instance
const app = cloudbase.init({
env: "your-env-id",
});
const res = await app.callFunction({
name: name: 'functionName', // cloud function name
data: {
// parameters passed to the cloud function
param1: 'value1',
param2: 'value2'
}
});
For details, please refer to: HTTP API
curl -L 'https://your-envId.api.tcloudbasegateway.com/v1/functions/:name' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
-d '{}'
⚠️ Note: HTTP API calls require a valid access token. Please refer to the authentication documentation to obtain an access token.
💡 Note: When using different SDKs, ensure that the environment ID and relevant authentication information are properly configured.