All Products
Search
Document Center

Function Compute:Use an HTTP trigger to invoke a function

Last Updated:Apr 01, 2026

An HTTP trigger exposes a function as an HTTP(S) endpoint, called a function URL. When a client calls the function URL, Function Compute converts the HTTP request into an event object and passes it to your function handler. After the function returns, Function Compute maps the output back to an HTTP response and sends it to the client.

This topic covers HTTP trigger behavior in built-in runtimes. For custom runtimes, see Web functions.

In Function Compute 3.0, HTTP trigger behavior in built-in runtimes differs notably from Function Compute 2.0. For custom runtimes and Custom Container runtimes, the behavior remains the same as in Function Compute 2.0.

How it works

image

When a client calls your function URL:

  1. Function Compute maps the HTTP request to an event object (event).

  2. The event object is passed to your function handler.

  3. After your function returns, Function Compute maps the output to an HTTP response and sends it back to the client.

Request struct

Format

Function Compute maps the incoming HTTP request to an event object with the following structure:

{
    "version": "v1",
    "rawPath": "/example",
    "body": "Hello FC!",
    "isBase64Encoded": false,
    "headers": {
        "header1": "value1",
        "header2": "value1,value2"
    },
    "queryParameters": {
        "parameter1": "value1",
        "parameter2": "value1,value2"
    },
    "requestContext": {
        "accountId": "123456*********",
        "domainName": "<http-trigger-id>.<region-id>.fcapp.run",
        "domainPrefix": "<http-trigger-id>",
        "http": {
            "method": "GET",
            "path": "/example",
            "protocol": "HTTP/1.1",
            "sourceIp": "11.11.11.**",
            "userAgent": "PostmanRuntime/7.32.3"
        },
        "requestId": "1-64f6cd87-*************",
        "time": "2023-09-05T06:41:11Z",
        "timeEpoch": "1693896071895"
    }
}

Parameters

ParameterDescriptionExample
versionPayload format version. The only supported value is v1.v1
rawPathURL-encoded request path. For a request URL like https://{url-id}.{region}.fcapp.run/example, this value is /example. For the decoded path, see requestContext.http.path./example
bodyRequest body. Binary data is Base64-encoded.Hello FC!
isBase64EncodedWhether the request body is Base64-encoded. Valid values: true, false.false
headersRequest headers as key-value pairs. If a key has multiple values, they are separated by commas. In Function Compute 3.0, the first letter of each header key is uppercased (normalization). See Why does the first letter of the header key become uppercase when I use an HTTP trigger to invoke a function?{"Header1": "value1", "Header2": "value1,value2"}
queryParametersQuery parameters as a JSON object. For a URL like https://{url-id}.{region}.fcapp.run/example?key1=value1, this value is {"key1": "value1"}. Multiple values for the same key are separated by commas.{"parameter1": "value1", "parameter2": "value1,value2"}
requestContextAdditional request metadata, including the request ID, timestamp, and caller information.
requestContext.accountIdID of the Alibaba Cloud account that owns the function.123456*********
requestContext.domainNameDomain name of the HTTP trigger.<http-trigger-id>.<region-id>.fcapp.run
requestContext.domainPrefixDomain prefix of the HTTP trigger.<http-trigger-id>
requestContext.http.methodHTTP method. Valid values: GET, POST, PUT, HEAD, OPTIONS, PATCH, DELETE.GET
requestContext.http.pathDecoded request path./example
requestContext.http.protocolRequest protocol.HTTP/1.1
requestContext.http.sourceIpPeer IP of the direct TCP connection (RemoteAddr). See the note below.11.11.XX.XX
requestContext.http.userAgentValue of the user-agent request header.PostmanRuntime/7.32.3
requestContext.requestIdRequest ID for tracing invocation logs.1-64f6cd87-*************
requestContext.timeRequest timestamp in ISO 8601 format.2023-09-05T06:41:11Z
requestContext.timeEpochRequest timestamp in UNIX time (milliseconds).1693896071895
Warning

sourceIp is the peer IP of the direct TCP connection, not necessarily the original client IP. If the request is not forwarded by a proxy, sourceIp is the client's IP. If the request passes through one or more proxies, sourceIp is the IP of the last proxy. To get the original client IP when requests go through proxies, read the X-Forwarded-For header. For details, see How do I obtain the original IP address of a client when an HTTP trigger invokes a function that uses a built-in runtime?

Mapping logic

Function Compute maps the HTTP request to the event object as follows:

  • HTTP request headers → event.headers

  • HTTP query parameters → event.queryParameters

  • Request context (request ID, timestamp, caller identity) → event.requestContext

  • POST request body → event.body

Base64 encoding

Function Compute checks the Content-Type header to decide whether to Base64-encode the request body.

Content-TypeisBase64EncodedBody handling
text/*falsePassed as-is
application/jsonfalsePassed as-is
application/ld+jsonfalsePassed as-is
application/xhtml+xmlfalsePassed as-is
application/xmlfalsePassed as-is
application/atom+xmlfalsePassed as-is
application/javascriptfalsePassed as-is
Any other valuetrueBase64-encoded before passing to function

Request mapping examples

GET

HTTP requestEvent object
GET /?parameter1=value1&parameter2=value2 HTTP/1.1{"version":"v1","rawPath":"/","headers":{"Accept":"*/*","User-Agent":"CurlHttpClient"},"queryParameters":{"parameter1":"value1","parameter2":"value2"},"body":"","isBase64Encoded":true,"requestContext":{"accountId":"1327**********","domainName":"example.cn-hangzhou.fcapp.run","domainPrefix":"example","requestId":"1-67aee50c-****-**********","time":"2025-02-14T06:39:08Z","timeEpoch":"1739515148145","http":{"method":"GET","path":"/","protocol":"HTTP/1.1","sourceIp":"40.XX.XX.XX","userAgent":"CurlHttpClient"}}}

To send this request from the CLI (replace https://example.cn-hangzhou.fcapp.run with your function URL):

curl -v "https://example.cn-hangzhou.fcapp.run?parameter1=value1&parameter2=value2"

POST

HTTP requestEvent object
POST / HTTP/1.1<br>Content-Type: application/json{"version":"v1","rawPath":"/","headers":{"Accept":"*/*","Content-Length":"20","Content-Type":"application/json","User-Agent":"curl/8.7.1"},"queryParameters":{},"body":"{\"message\": \"Hello\"}","isBase64Encoded":false,"requestContext":{"accountId":"1327**********","domainName":"example.cn-hangzhou.fcapp.run","domainPrefix":"example","requestId":"1-67aee50c-****-**********","time":"2025-02-14T06:39:08Z","timeEpoch":"1739515148145","http":{"method":"POST","path":"/","protocol":"HTTP/1.1","sourceIp":"40.XX.XX.XX","userAgent":"CurlHttpClient"}}}

To send this request from the CLI (replace https://example.cn-hangzhou.fcapp.run with your function URL):

curl -v -H "Content-Type: application/json" -d '{"message": "Hello"}' "https://example.cn-hangzhou.fcapp.run"
To force Base64 encoding of the request body, set Content-Type to application/x-www-form-urlencoded.

Response struct

Format

Your function output is parsed into a response struct before being mapped to the HTTP response:

{
    "statusCode": 200,
    "headers": {
        "Content-Type": "application/json",
        "Custom-Header-1": "Custom Value"
    },
    "isBase64Encoded": false,
    "body": "{\"message\":\"Hello FC!\"}"
}

Mapping logic

Function Compute maps your function output to the HTTP response based on whether the output is valid JSON containing a statusCode field.

When the output is valid JSON with `statusCode`:

Response struct fieldHTTP response
statusCodeStatus code
headers["Content-Type"]Content-Type header (defaults to application/json if absent)
bodyResponse body
isBase64EncodedWhether to Base64-decode the body before sending (defaults to false if absent)

When the output is valid JSON without `statusCode`, or is not JSON:

Function Compute uses the following defaults:

FieldDefault value
statusCode200
Content-Typeapplication/json
bodyFunction output as-is
isBase64Encodedfalse

Response mapping examples

The following examples show how function output flows through parsing to the final HTTP response.

Output for a string response

Function outputParsed response structHTTP response (client receives)
Hello World!{"statusCode":200,"body":"Hello World!","headers":{"content-type":"application/json"},"isBase64Encoded":false}HTTP/1.1 200 OK<br>Content-Disposition: attachment<br>Content-Length: 12<br>Content-Type: application/json<br>X-Fc-Request-Id: 1-64f6d6e7-e01edb1cce58240ed59b59d9<br><br>Hello World!

Output for a JSON response

Function outputParsed response structHTTP response (client receives)
{"message": "Hello World!"}{"statusCode":200,"body":"{\"message\": \"Hello World!\"}","headers":{"content-type":"application/json"},"isBase64Encoded":false}HTTP/1.1 200 OK<br>Content-Disposition: attachment<br>Content-Length: 27<br>Content-Type: application/json<br>X-Fc-Request-Id: 1-64f6d867-7302fc1ac6338b6fd2adb782<br><br>{"message": "Hello World!"}

Output for a custom response

Function outputParsed response structHTTP response (client receives)
{"statusCode":201,"headers":{"Content-Type":"application/json","My-Custom-Header":"Custom Value"},"body":{"message":"Hello, world!"},"isBase64Encoded":false}{"statusCode":201,"headers":{"Content-Type":"application/json","My-Custom-Header":"Custom Value"},"body":{"message":"Hello, world!"},"isBase64Encoded":false}HTTP/1.1 201 OK<br>Content-Type: application/json<br>My-Custom-Header: Custom Value<br>X-Fc-Request-Id: 1-64f6dcb3-e787580749d3ba13b047ce14<br><br>{"message": "Hello world!"}

Base64 decoding

If your function returns valid JSON with isBase64Encoded set to true, Function Compute Base64-decodes the body before mapping it to the HTTP response body. If decoding fails, Function Compute returns the body value directly without reporting an error.

Response headers

Function Compute automatically adds the X-Fc-Request-Id header to every response. This header uniquely identifies the request and is useful for tracing logs and diagnosing errors.

Warning

Custom headers with the X-Fc- prefix are not supported. The following headers are reserved by Function Compute and are ignored if returned by your function:

  • connection

  • content-length

  • date

  • keep-alive

  • server

  • content-disposition

Error handling

HTTP trigger invocations and direct API invocations handle function errors differently.

Invocation typeError behaviorHTTP status code
Direct API invocationError message returned in the response body200
HTTP trigger (function URL)Error message hidden; Internal Server Error returned502

When a function invoked via HTTP trigger encounters an error, the client receives a response like:

HTTP/1.1 502 Bad Gateway
Content-Disposition: attachment
Content-Type: application/json
X-Fc-Request-Id: 1-64f6df91-fe144d52e4fd27afe3d8dd6f
Content-Length: 21

Internal Server Error

Use the X-Fc-Request-Id value to look up the full error details in your function's invocation logs.

Related topics

If you are writing function code for a built-in runtime, see the handler documentation for your language: