HTTP Access Service
HTTP Access Service enables developers to access their own cloud development resources via HTTP.
Starting from version 3.4.0+, a new access
service interface has been added. You can use the new interface. The original SDK can be migrated to the new interface, or continue using the old interface.
All the following interfaces were added in version 3.4.0+.
Create HTTP Access Service
1. Interface Description
Function: Create HTTP Access Service.
Interface declaration: async createAccess(options: ICreateAccessOptions): Promise<ICreateRes>
2. Input Parameters
Field | Required | Type | Description |
---|---|---|---|
path | Yes | String | Access path must start with / |
name | Yes | String | Bound service name |
type | Yes | Number | Bound service type: Cloud Function: 1, Serverless Cloud Application: 2 |
auth | No | Boolean | Whether to enable authentication for the path corresponding to the HTTP access service |
3. Response
Field | Required | Type | Description |
---|---|---|---|
RequestId | Yes | String | Request unique identifier |
APIId | Yes | String | HTTP access service Id |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const app = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // CloudBase environment ID, obtain from the Tencent CloudBase Console
});
async function test() {
const res = await app.access.createAccess({
path: "/sum",
type: 1,
name: "sum",
});
const { APIId } = res;
console.log(APIId);
}
test();
Get HTTP Access Service
1. Interface Description
Function: Get HTTP Access Service
Interface declaration: async getAccessList(options: IGetOptions): Promise<IGetRes>
2. Input Parameters
Field | Required | Type | Description |
---|---|---|---|
path | No | String | Access path must start with / |
name | No | String | Bound service name |
offset | No | Number | Offset for querying the List |
limit | No | Number | Number of records returned per query |
3. Response
Field | Type | Description |
---|---|---|
RequestId | String | Request unique identifier |
APISet | Array<CloudBaseGWAPI> | HTTP access service list |
Total | Number | Total number of HTTP access services |
EnableService | Boolean | Whether the HTTP access service is enabled |
CloudBaseGWAPI
Field | Type | Description |
---|---|---|
APIId | String | APIId |
Path | String | Custom path |
Type | Number | service type, Cloud Function defaults to 1 |
Name | String | Cloud function name |
CreateTime | Number | service creation time |
EnvId | String | Environment ID |
EnableAuth | Boolean | Whether authentication is enabled for the path corresponding to the HTTP access service |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // CloudBase environment ID, obtain from the Tencent CloudBase Console
});
async function test() {
const res = await app.access.getAccessList();
console.log(res);
}
test();
Delete HTTP Access Service
1. Interface Description
Function: Delete Bound HTTP Access Service
Interface declaration: async deleteAccess(options: IDeleteOptions): Promise<IDeleteRes>
2. Input Parameters
Field | Required | Type | Description |
---|---|---|---|
name | No | String | Bound service name |
type | No | String | Bound service type, Cloud Function: 1, Serverless Cloud Application: 2 |
apiId | No | String | HTTP access service Id |
path | No | String | HTTP access service access path |
The
deleteAccess` interface supports three deletion conditions:
- Delete by bound service name, i.e., using the
name
andtype
options, which will delete all access paths bound to this service - Delete by service Id, i.e., the
apiId
option - By access path, i.e., the
path
option
3. Response
Field | Required | Type | Description |
---|---|---|---|
RequestId | Yes | String | Request unique identifier |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // CloudBase environment ID, obtain from the Tencent CloudBase Console
});
async function test() {
const res = await app.access.deleteAccess({
name: "sum",
});
}
test();
Switch HTTP Access Service Authentication
1. Interface Description
Function: Switch HTTP Access Service Authentication, Globally Effective
Interface declaration: async switchAuth(auth: boolean): Promise<IUpdateRes>
2. Input Parameters
Field | Required | Type | Description |
---|---|---|---|
auth | Yes | Boolean | Whether to enable HTTP access service authentication, true enables, false disables |
3. Response
Field | Required | Type | Description |
---|---|---|---|
RequestId | Yes | String | Request unique identifier |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // CloudBase environment ID, obtain from the Tencent CloudBase Console
});
async function test() {
const res = await app.access.switchAuth(false);
console.log("Switch Authentication", res);
}
test();
Switch HTTP Access Service Path Authentication
1. Interface Description
Function: Switch HTTP Access Service Path Authentication, Only Takes Effect on a Single Path
Interface declaration: async switchPathAuth(options: IUpdateOptions)
2. Input Parameters
Field | Required | Type | Description |
---|---|---|---|
apiIds | Yes | Array<String> | HTTP access service Id list |
auth | Yes | Boolean | Whether to enable service authentication, true enables, false disables |
3. Response
Field | Required | Type | Description |
---|---|---|---|
RequestId | Yes | String | Request unique identifier |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // CloudBase environment ID, obtain from the Tencent CloudBase Console
});
async function test() {
const res = await app.access.switchPathAuth({
apiIds: ["xxxxx"],
auth: false,
});
}
test();
Adding a Custom Domain to HTTP Access Service
1. Interface Description
Function: Add a custom domain
Interface declaration: async addCustomDomain(options: IDomainOptions): Promise<IAddRes>
When binding a custom domain, be sure to configure CNAME resolution with your domain name provider
2. Input Parameters
Field | Required | Type | Description |
---|---|---|---|
domain | Yes | String | Custom domain |
certId | No | String | Tencent Cloud SSL certificate Id. The SSL certificate must be under the calling account. |
3. Response
Field | Required | Type | Description |
---|---|---|---|
RequestId | Yes | String | Request unique identifier |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // CloudBase environment ID, obtain from the Tencent CloudBase Console
});
async function test() {
const res = await app.access.addCustomDomain({
domain: "xxx",
certId: "xxx",
});
}
test();
List Custom Domains for HTTP Access Service
1. Interface Description
Function: List custom domains
Interface declaration: async getDomainList(): Promise<IDomainRes>
2. Input Parameters
None
3. Response
Field | Type | Description |
---|---|---|
RequestId | String | Request unique identifier |
DefaultDomain | String | Default domain for HTTP access service |
EnableService | Boolean | Whether the HTTP access service is enabled |
ServiceSet | Array<IService> | HTTP access service domain list |
IService
Field | Type | Description |
---|---|---|
Domain | String | Domain name |
OpenTime | Number | Activation time |
Status | Number | Binding status: 1 (Binding in progress), 2 (Binding failed), 3 (Binding succeeded) |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // CloudBase environment ID, obtain from the Tencent CloudBase Console
});
async function test() {
const res = await app.access.getDomainList();
}
test();
Deleting a Custom Domain for HTTP Access Service
1. Interface Description
Function: Delete a custom domain
Interface declaration: async deleteCustomDomain(domain: string): Promise<IDeleteRes>
2. Input Parameters
Field | Required | Type | Description |
---|---|---|---|
domain | Yes | String | Custom domain |
3. Response
Field | Type | Description |
---|---|---|
RequestId | String | Request unique identifier |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId", // CloudBase environment ID, obtain from the Tencent CloudBase Console
});
async function test() {
const res = await app.access.deleteCustomDomain("xxxx");
}
test();