API Gateway-type trigger

Prev Next

Available in Classic

You can add API Gateway type triggers on NAVER Cloud Platform console's Cloud Functions > Action > Action details. API Gateway is a service that can perform all API-related tasks including API calls, management, and monitoring.

Note

Additional fees apply when you subscribe to API Gateway. For information on API Gateway and its pricing plans, see Services > Application Services > API Gateway menu in NAVER Cloud Platform portal.

Add trigger

To add an API Gateway-type trigger, select API Gateway from trigger types then configure API Gateway connection information.

cloudfunctions-apigateway-vpc_v2_01_ko

Trigger types

API Gateway trigger types vary depending on the action type you want to connect. When connecting web actions or sequence web actions, HTTP-type API Gateway triggers are created. When connecting basic actions or sequence actions, webhook-type API Gateway triggers are created. Descriptions of each type are as follows:

HTTP type

  • Implements REST APIs by directly handling HTTP requests/responses.
  • Supports POST, GET, OPTIONS, PUT, DELETE, PATCH, HEAD methods.
  • Passes HTTP request headers, parameters, paths, and body values to actions.
  • Can receive status codes, headers, and body defined in action code as HTTP responses.

Webhook type

  • Can run actions through HTTP requests.
  • Supports POST method.
  • Supports synchronous (request and reply) and asynchronous (fire and forget) methods from action code returns. For more detailed description, see Query parameters.

Configure API Gateway

Configure API Gateway endpoints to run actions. For detailed API Gateway configuration, see API Gateway user guide.

Product

  • Unit for managing multiple APIs, provides call domains for each Product.

API

  • Unit for managing API specifications and overview where you can define related resources and methods and configure authentication methods.

Resource

  • Can configure API URL paths (endpoints).
  • For HTTP type, specify resource value as {type+}to reference paths including called sub-resources in action code.
  • Cannot select if same method already exists under selected resource.

Stage

  • API deployment unit that can be created and operated as development, test, production, or version codes (v 0.0.1).
  • Select existing API Gateway deployment Stage or create new one.

API Key authentication

  • Calls APIs using your API key when enabled.

Authentication

  • Uses IAM authentication provided by NAVER Cloud Platform to protect APIs.
    • NONE: no authentication
    • IAM: uses IAM authentication provided by NAVER Cloud Platform
    • IAM+AUTHORIZATION: uses NAVER Cloud Platform's IAM user authentication and method-level authorization

Run trigger

Endpoint

The run endpoint of the API Gateway trigger to run actions is created in the following format.

https://{product_id}.apigw.ntruss.com/{api_name}/{stage_name}/{resource_name}

HTTP request

Request method

HTTP type

  • Supports all POST, GET, OPTIONS, PUT, DELETE, PATCH, HEAD methods.

Webhook type

  • Supports POST method.

Request headers

HTTP type

  • Allows all content types and can reference request headers in action code.

Webhook type

  • Allows only application/json content type.

Query parameters

HTTP type

  • Passes query parameter values to action code for use.
  • To reference query parameters, enable Use HTTP raw data on connected action.

Webhook type

  • Cannot reference query parameter values in action code.
  • Use following query parameters to adjust API call handling and results during runs:
  • blocking
    • true
      • Synchronous (request and reply) request
      • Receive HTTP response after action completes and action results are passed as response body.
      • Switch to asynchronous call if action exceeds 1 minute.
    • false
      • Asynchronous (fire and forget) request. Default.
      • Return HTTP response immediately regardless of action success or fail with only action history ID (activation ID) in response body.
  • result
    • true
      • Pass action code return value as HTTP response body.
    • false

Request body

HTTP type

  • For application/json content type, Cloud Functions system controller automatically converts and passes to action parameters in Key/Value format.
  • For other content types, enable Use HTTP raw data on connected action for processing.
  • Pass text content types as plain text to action and encode binary types in Base64.

Webhook type

  • Receives request body JSON data as action runtime parameters.

Events forwarded to action

HTTP request event data is passed as action runtime parameters.

HTTP type

{
    "__ow_headers": {
        "content-type": "application/json"
    },
    "__ow_method": "post",
    "__ow_path": "/",
    "__ow_query": "key1=value1&key2=value2",
    "__ow_body": "eyJhIjogImIiLCAiYyI6IDF9",
}

Webhook type

{
    "name": "Cloud Functions"
}

HTTP response

HTTP type

Defines headers, body, and status code in JSON format in action return values. Cloud Functions system controller converts these to HTTP response format.

  • headers: json object with header names as keys and string, number, or boolean values
  • statusCode: HTTP status code Default is 200 OK. If body is null, empty string (""), or undefined, processes as 204 No Content.
  • body: defines response body using plain text, JSON objects, array strings, base64 encoded binary data. Default is empty response.
// Content-Type: JSON
{
    statusCode: 200,
    headers: {
        "Content-Type": "application/json"
    },
    body: {"key":"value"}
}

// Content-Type: HTML 
{
    "statusCode": 200,
    "headers": {
        "Content-Type": "text/html"
    },
    "body": "<html><body><h3>hello</h3></body></html>" }
}

// Content-Type: TEXT 
{
    "statusCode": 200,
    "headers": {
        "Content-Type": "text/plain"
    },
    "body": "hello" }
}

// Content-Type: Image 
{
    "statusCode": 200,
    "headers": {
        "Content-Type": "image/png"
    },
    "body": "<base64 encoded string>" }
}

// HTTP Redirect
{
    "statusCode": 302,
    "headers": { 
        "location": "https://www.ncloud.com"
    }
}

// Header cookie settings
{
    "statusCode": 302,
    "headers": { 
        "Set-Cookie": "UserID=Jane; Max-Age=3600; Version=",
        "Content-Type": "text/html"
    },
    "body": "<html><body><h3>hello</h3></body></html>"
}
Note

OPTIONS requests automatically add Cors headers to response headers. These headers allow all Origins and OPTIONS, GET, DELETE, POST, PUT, HEAD, PATCH methods. Additionally, Access-Control-Request-Headers echoes back as Access-Control-Allow-Headers when HTTP requests exist. The default values are created as follows:

Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: OPTIONS, GET, DELETE, POST, PUT, HEAD, PATCH
Access-Control-Allow-Headers: Authorization, Content-Type

Web actions can manually handle OPTIONS requests. Enable Header option settings for this. CORS headers are no longer added automatically and must be defined directly in action code.

Caution
  • HTTP type can receive responses for up to 1 minute. Actions running longer than 1 minute receive 202 Accepted response with errors included in the body.
{
    "code": "fe398a568d89a5efbeaedbb5bc415cbb",
    "error": "Response not yet ready."
}
  • Actions have a maximum response size limit. If response values exceed this limit, the action result is marked as failed. When returning object files like images, take note of the maximum response size. If exceeding the limit, use alternative storage instead of returning through the action code. For maximum response size specifications, see Cloud Functions prerequisites.

Webhook type

Can only define body.

  • Status code: 200 OK for synchronous. 202 Accepted for asynchronous
  • Body: action code return value for synchronous. Action run history ID for asynchronous
Caution

In synchronous mode, switches to asynchronous if action runs over 1 minute.

Run examples

HTTP type

  • Action return value
{
    "statusCode": 200,
    "headers": {
            "Custom-Header": "custom value"
            "Content-Type": "application/json"
        },
    "body": {"name": "Cloud Functions"}
}
  • Run
$ curl -i -X GET "https://myproduct.apigw.ntruss.com/api/v1/users" 

HTTP/2 200
content-type: application/json
custom-header: custom value
x-request-id: c64b4dc037c7be7bbe73213beacff8eb
x-ncp-apigw-response-origin: ENDPOINT

{
    "name": "Cloud Functions"
}

Webhook type

  • Action return value
{
    "name": "Cloud Functions"
}
  • Run (synchronous)
$ curl -i -X POST -H "Content-Type: application/json" "https://myproduct.apigw.ntruss.com/api/v1/action?blocking=true&result=true -d '{"key1": "value1"}'


HTTP/2 200
content-type: application/json
x-request-id: c64b4dc037c7be7bbe73213beacff8eb
x-ncp-apigw-response-origin: ENDPOINT

{"name":"Cloud Functions"}
  • Run (asynchronous)
$ curl -i -X POST -H "Content-Type: application/json" "https://myproduct.apigw.ntruss.com/api/v1/action?blocking=false -d '{"key1": "value1"}'

HTTP/2 202
content-type: application/json
x-request-id: c64b4dc037c7be7bbe73213beacff8eb
x-ncp-apigw-response-origin: ENDPOINT

{"activationId":"e04d1a62a3e14eb58d1a62a3e18eb590"}