tencent cloud

Serverless Cloud Function

Function URL Overview

PDF
포커스 모드
폰트 크기
마지막 업데이트 시간: 2025-06-17 16:40:37

Overview

A function URL is a dedicated HTTP(S) endpoint for a function. After configuring a function URL for a function, you can invoke the function through its HTTP(S) endpoint using a Web browser, curl, Postman, or any HTTP client.
You can create and configure a function URL through the SCF console or SCF API/CLI. Once a function URL is created, its URL endpoint will remain unchanged permanently. The endpoint format of the function URL is as follows:
public network: https://<app-id>-<url-id>.<region>.tencentscf.com
private network: https://<app-id>-<url-id>.in.<region>.tencentscf.com
Function URL and trigger exist at the same level, suitable for event functions and Web functions. You can enable function URL and concurrently configure triggers such as API Gateway.
Function URL is one-to-one bound to the version and alias of a function. You need to manually turn on or off the function URL for each version and alias. By default, the function URL is off.
Notes:
If need to generate a WSS address,please enable a WebSocket support in the function configuration.

Calling Parameter

Event Function

Request parameters.

When the URL receives a request, the function will be triggered to run. At the same time, the URL will send the relevant information of the request to the triggered function in the form of an event input parameter. The relevant information of the request contains, for example, the specific service and API rule that received the request, the actual path of the request, the method, the request path, headers, query, etc.
// Example of Event detailed information [compatible with apigw protocol, remove relevant fields such as headerParameters, isBase64Encoded, pathParameters, queryStringParameters, requestContext]
{
"body":"{\\"test\\":\\"hello world\\"}",
"headers":{
"accept":"*/*",
"accept-encoding":"gzip, deflate, br",
"cache-control":"no-cache",
"connection":"keep-alive",
"content-length":"17",
"x-scf-remote-addr":"111.206.96.145" // this field is the client request IP
},
"httpMethod":"POST",
"path":"/",
"queryString":{
"a":"1",
"b":"2"
}
}

Response Parameters

When the function returns a response, the function parses the response and converts it to an HTTP response. Standard response payload:
{
"statusCode": 201,
"headers": {
"Content-Type": "application/json",
"My-Custom-Header": "Custom Value"
},
"body": "{ \\"message\\": \\"Hello, world!\\" }"
}
The function will infer the response format for you. If your function returns valid JSON and does not return a statusCode, the function assumes the statusCode is 200, the content-type is application/json, and the body is the function response.
The standard response parameter format of the function response is as follows:
Function output
HTTP response (the content seen by the client)
"Hello, world!"
HTTP/2 200
date: Wed, 08 Sep 2021 18:02:24 GMT
content-type: application/json
content-length: 15

"Hello, world!"
{
"message": "Hello, world!"
}
HTTP/2 200
date: Wed, 08 Sep 2021 18:02:24 GMT
content-type: application/json
content-length: 34

{
"message": "Hello, world!"
}
{
"statusCode": 201,
"headers": {
"Content-Type": "application/json",
"My-Custom-Header": "Custom Value"
},
"body": JSON.stringify({
"message": "Hello, world!"
})
}
HTTP/2 201
date: Wed, 08 Sep 2021 18:02:24 GMT
content-type: application/json
content-length: 27
my-custom-header: Custom Value

{
"message": "Hello, world!"
}

Web Function

When the URL receives an HTTP request, the function will be triggered to execute. At this time, the URL will directly forward the HTTP request without performing event type format conversion. Meanwhile, the request response is also directly forwarded.


도움말 및 지원

문제 해결에 도움이 되었나요?

피드백