API Gateway

Tencent Serverless Cloud Functions can create function based API endpoints through API Gateway.

It might be helpful to read the Tencent Serverless Cloud Functions API Gateway Trigger to learn the full functionality.

HTTP Endpoint

This setup specifies that the function should be run when someone accesses the API gateway via a POST request.

Here's an example:

    handler: index.main_handler
    runtime: Nodejs8.9

      - apigw:
          name: hello_world_apigw
            stageName: release
            serviceId: # if you don't specify an existing serviceId, a new service will be created by default.
            httpMethod: POST
            integratedResponse: true # enable integrated response
exports.main_handler = async (event, context, callback) => {
  return {
    isBase64Encoded: false,
    statusCode: 200,
    headers: { 'Content-Type': 'text/html' },
    body: 'hello world',

Event message structures of integration request for API Gateway trigger

When an API Gateway trigger receives a request, it sends the event data to the bound function in JSON format as shown below.

  "requestContext": {
    "serviceId": "service-f94sy04v",
    "path": "/test/{path}",
    "httpMethod": "POST",
    "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef",
    "identity": {
      "secretId": "abdcdxxxxxxxsdfs"
    "sourceIp": "",
    "stage": "release"
  "headers": {
    "Accept-Language": "en-US,en,cn",
    "Accept": "text/html,application/xml,application/json",
    "Host": "service-3ei3tii4-251000691.ap-guangzhou.apigateway.myqloud.com",
    "User-Agent": "User Agent String"
  "body": "{\"test\":\"body\"}",
  "pathParameters": {
    "path": "value"
  "queryStringParameters": {
    "foo": "bar"
  "headerParameters": {
    "Refer": ""
  "stageVariables": {
    "stage": "release"
  "path": "/test/value",
  "queryString": {
    "foo": "bar",
    "bob": "alice"
  "httpMethod": "POST"
Go to Github