Overview
The CloudBase HTTP API is a set of interfaces for accessing CloudBase platform features via the HTTP protocol, supporting functionalities such as databases, data models, user authentication, cloud functions, cloud hosting, cloud storage, AI, etc.
Prerequisites
Before you begin, make sure you have completed the following preparations:
- Enable the CloudBase environment: Enable the CloudBase environment
- Security Configuration: If you wish to call from the browser side, ensure that your environment is configured with CloudBase/Security Sources to allow cross-origin calls.
- Local development samples:
localhost:3000,127.0.0.1:3000 - Production environment example: Your actual domain
- Use the online debugging tool:
docs.cloudbase.net
- Local development samples:
⚠️ Note: Browser-side calls must be configured with security sources; otherwise, requests will fail due to cross-origin restrictions.
Authentication and Authorization
To call the CloudBase HTTP API, authentication and authorization are required. Please select the appropriate authentication method based on your application scenarios:
- AccessToken Authentication
- Tencent Cloud Signature V3 Authentication
Applicable Environment: Client/Server
Applicable Identity: User identity
Commonly used in client applications (such as mobile apps, Web front-ends) to access backend services, supporting granular access control for user identities.
Obtaining Method: Refer to Obtaining AccessToken
💡 Note: When using AccessToken to access APIs, you can control user and role permissions for each API via CloudBase Platform/Policy Management.
Applicable Environment: Server
Applicable Identity: Developer identity
Applicable for communication between servers, particularly for high-security management operations such as the creation, updating, and deletion of cloud resources.
Configuration Method: Refer to Tencent Cloud Signature V3
⚠️ Note: Currently, the
data modelanduser authenticationinterfaces do not support Tencent Cloud Signature V3 authentication.
Call Endpoint
The CloudBase HTTP API uses a unified domain name for API calls via a domain that varies depending on the region to which the environment belongs.
If your environment is located in Mainland China regions such as Shanghai (ap-shanghai), use the following domain name for API calls:
https://{your-env}.api.tcloudbasegateway.com
where {your-env} needs to be replaced with the actual environment ID. For example, if the environment ID used is cloud1-abc, the call endpoint would be:
https://cloud1-abc.api.tcloudbasegateway.com
If your environment is located in overseas regions such as Singapore (ap-singapore), the following domain name should be used for API calls:
https://{your-env}.api.intl.tcloudbasegateway.com
where {your-env} needs to be replaced with the actual environment ID. For example, if the environment ID used is cloud1-abc, the call endpoint would be:
https://cloud1-abc.api.intl.tcloudbasegateway.com
Usage Example
Cloud Function Invocation Sample
The following sample shows how to invoke a Cloud Function via the HTTP API:
- cURL
- JavaScript
- Python
curl -X POST "https://your-env-id.api.tcloudbasegateway.com/v1/functions/YOUR_FUNCTION_NAME" \
-H "Authorization: Bearer <access_token/apikey/publishable_key>" \
-H "Content-Type: application/json" \
-d '{
"name": "Zhang San",
"age": 25
}'
const response = await fetch(
"https://your-env-id.api.tcloudbasegateway.com/v1/functions/YOUR_FUNCTION_NAME",
{
method: "POST",
headers: {
Authorization: "Bearer <access_token/apikey/publishable_key>",
"Content-Type": "application/json",
},
body: JSON.stringify({
name: name: "Zhang San",
age: 25,
}),
}
);
const result = await response.json();
console.log("Function return result:", result);
import requests
import json
def call_cloud_function():
url = "https://your-env-id.api.tcloudbasegateway.com/v1/functions/YOUR_FUNCTION_NAME"
headers = {
"Authorization": "Bearer <access_token/apikey/publishable_key>",
"Content-Type": "application/json"
}
data = json.dumps({
"name": "Zhang San",
"age": 25
})
response = requests.post(url, headers=headers, data=data)
result = response.json()
print("Function return result:", result)
return result
When the Cloud Function is successfully invoked, the API returns a response in the following format:
{
"result": "Function execution result",
"requestId": "request ID",
"timestamp": 1640995200000
}
If the invocation fails, the error response format is as follows:
{
"code": "FUNCTION_PARAM_INVALID",
"message": "Parameter error details",
"requestId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
Online Debugging Tool
The Cloud Development Platform provides an online debugging tool that allows you to test API interfaces without writing code:
- Access the API documentation page
- Find the debugging tool entry
- Fill in the environment ID and request parameters
- Click to send the request and view the response.