Skip to main content

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:

  1. Enable the CloudBase environment: Enable the CloudBase environment
  2. 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

⚠️ 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:

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.

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

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:

  1. Access the API documentation page
  2. Find the debugging tool entry
  3. Fill in the environment ID and request parameters
  4. Click to send the request and view the response.