HTTP API Quick Start
The Cloud Development HTTP API is a set of interfaces designed for developers, aimed at providing access to Cloud Development platform functionalities from both client and server sides via the HTTP protocol. These APIs allow developers to programmatically implement features such as user authentication, cloud functions, data models, AI, etc., thereby accelerating the application development process.
HTTP API is a universal access method that can be used across any platform/language. This article will take the Javascript language as an example to demonstrate how to use the HTTP API.
Use AI to integrate CloudBase HTTP API in apps
In the HTTP API Documentation, we provide code generation capabilities for accessing interfaces in multiple languages, including C++, Java, Go, and more. Select your language, copy and paste to integrate the HTTP API into your application.
Prerequisites
Before using the HTTP API for specific modules, ensure that HTTP API permissions are enabled for the corresponding roles.
- Go to Cloud Admin Console -> Access Control -> Policy Management
- Configure access policies for Open APIs (HTTP API) of each module for the role.
1. Authentication
Anonymous Login
const env = "your-env-id";
const deviceId = Math.random().toString(36).substring(2, 15); // Randomly generated and should be cached on the client side
const { token_type, access_token } = await (
await fetch(
`https://${env}.api.tcloudbasegateway.com/auth/v1/signin/anonymously`,
{
method: "POST",
headers: {
"x-device-id": deviceId,
},
}
)
).json();
console.log(token_type, access_token);
Username/Password Login
const env = "your-env-id";
const deviceId = Math.random().toString(36).substring(2, 15); // Randomly generated and should be cached on the client side
const { token_type, access_token } = await (
await fetch(`https://${env}.api.tcloudbasegateway.com/auth/v1/signin`, {
method: "POST",
headers: {
"x-device-id": deviceId,
},
body: JSON.stringify({
password: "your-password",
username: "your-username",
}),
})
).json();
console.log(token_type, access_token);
For details, refer to the User Authentication HTTP API