Skip to main content

Edge Route Policy Module

Replace HTTPS Edge Route Policies Module

Request

PUT /edges/https/{edge_id}/routes/{id}/policy

Example Request

curl \
-X PUT \
-H "Authorization: Bearer {API_KEY}" \
-H "Content-Type: application/json" \
-H "Ngrok-Version: 2" \
-d '{"enabled":true,"inbound":[{"actions":[{"config":{"from":"v0/user/([0-9]+).*","to":"v1/user?id=$1&$args"},"type":"url-rewrite"},{"config":{"from":"v0/super/secret/path/to/admin.*","to":"v1/admin?$is_args$args"},"type":"url-rewrite"}],"expressions":["req.URL.contains('v0/')"],"name":"Rewrite v0 API Calls to v1."},{"actions":[{"config":{"content":"access denied","headers":{"content-type":"text/plain"},"status_code":401},"type":"custom-response"}],"expressions":["req.Method == 'POST' && req.ContentLength > 10000","conn.Geo.CountryCode in ['BR', 'CN', 'CU', 'IR', 'NG', 'RO', 'RU', 'SD', 'SY', 'UA']"],"name":"Block POST Requests With Large Content Length From Specific Countries"},{"actions":[{"config":{"status_code":400},"type":"deny"}],"expressions":["'ChatGPT' in req.Headers['User-Agent'] || 'GPTBot' in req.Headers['User-Agent']"],"name":"Block AI Crawler Bots"}],"outbound":[{"actions":[{"config":{"metadata":{"edgeId":"edghts_2fKmctp7pQGnDcS5wMZ3EpALwAV","message":"Unsuccessful response","routeId":"edghtsrt_2fKmcqaUXNXC8riDf9GTOMcVB7T"}},"type":"log"}],"expressions":["res.StatusCode < '200' || res.StatusCode > '300'"],"name":"Log Unsuccessful Response"}]}' \
https://api.ngrok.com/edges/https/edghts_2fKmctp7pQGnDcS5wMZ3EpALwAV/routes/edghtsrt_2fKmcqaUXNXC8riDf9GTOMcVB7T/policy

Parameters

NameTypeDescription
enabledbooleantrue if the module will be applied to traffic, false to disable. default true if unspecified
inboundEndpointRulethe inbound rules of the traffic policy.
outboundEndpointRulethe outbound rules on the traffic policy.

EndpointRule parameters

NameTypeDescription
expressionsList<string>cel expressions that filter traffic the policy rule applies to.
actionsEndpointActionthe set of actions on a policy rule.
namestringthe name of the rule that is part of the traffic policy.

EndpointAction parameters

NameTypeDescription
typestringthe type of action on the policy rule.
configobjectthe configuration for the action on the policy rule.

Response

Returns a 200 response on success

Example Response

{
"enabled": true,
"inbound": [
{
"actions": [
{
"config": {
"from": "v0/user/([0-9]+).*",
"to": "v1/user?id=$1&$args"
},
"type": "url-rewrite"
},
{
"config": {
"from": "v0/super/secret/path/to/admin.*",
"to": "v1/admin?$is_args$args"
},
"type": "url-rewrite"
}
],
"expressions": ["req.URL.contains('v0/')"],
"name": "Rewrite v0 API Calls to v1."
},
{
"actions": [
{
"config": {
"content": "access denied",
"headers": {
"content-type": "text/plain"
},
"status_code": 401
},
"type": "custom-response"
}
],
"expressions": [
"req.Method == 'POST' && req.ContentLength > 10000",
"conn.Geo.CountryCode in ['BR', 'CN', 'CU', 'IR', 'NG', 'RO', 'RU', 'SD', 'SY', 'UA']"
],
"name": "Block POST Requests With Large Content Length From Specific Countries"
},
{
"actions": [
{
"config": {
"status_code": 400
},
"type": "deny"
}
],
"expressions": [
"'ChatGPT' in req.Headers['User-Agent'] || 'GPTBot' in req.Headers['User-Agent']"
],
"name": "Block AI Crawler Bots"
}
],
"outbound": [
{
"actions": [
{
"config": {
"metadata": {
"edgeId": "edghts_2fKmctp7pQGnDcS5wMZ3EpALwAV",
"message": "Unsuccessful response",
"routeId": "edghtsrt_2fKmcqaUXNXC8riDf9GTOMcVB7T"
}
},
"type": "log"
}
],
"expressions": ["res.StatusCode < '200' || res.StatusCode > '300'"],
"name": "Log Unsuccessful Response"
}
]
}

Fields

NameTypeDescription
enabledbooleantrue if the module will be applied to traffic, false to disable. default true if unspecified
inboundEndpointRulethe inbound rules of the traffic policy.
outboundEndpointRulethe outbound rules on the traffic policy.

EndpointRule fields

NameTypeDescription
expressionsList<string>cel expressions that filter traffic the policy rule applies to.
actionsEndpointActionthe set of actions on a policy rule.
namestringthe name of the rule that is part of the traffic policy.

EndpointAction fields

NameTypeDescription
typestringthe type of action on the policy rule.
configobjectthe configuration for the action on the policy rule.

Get HTTPS Edge Route Policies Module

Request

GET /edges/https/{edge_id}/routes/{id}/policy

Example Request

curl \
-X GET \
-H "Authorization: Bearer {API_KEY}" \
-H "Ngrok-Version: 2" \
https://api.ngrok.com/edges/https/edghts_2fKmctp7pQGnDcS5wMZ3EpALwAV/routes/edghtsrt_2fKmcqaUXNXC8riDf9GTOMcVB7T/policy

Response

Returns a 200 response on success

Example Response

{
"enabled": true,
"inbound": [
{
"actions": [
{
"config": {
"from": "v0/user/([0-9]+).*",
"to": "v1/user?id=$1&$args"
},
"type": "url-rewrite"
},
{
"config": {
"from": "v0/super/secret/path/to/admin.*",
"to": "v1/admin?$is_args$args"
},
"type": "url-rewrite"
}
],
"expressions": ["req.URL.contains('v0/')"],
"name": "Rewrite v0 API Calls to v1."
},
{
"actions": [
{
"config": {
"content": "access denied",
"headers": {
"content-type": "text/plain"
},
"status_code": 401
},
"type": "custom-response"
}
],
"expressions": [
"req.Method == 'POST' && req.ContentLength > 10000",
"conn.Geo.CountryCode in ['BR', 'CN', 'CU', 'IR', 'NG', 'RO', 'RU', 'SD', 'SY', 'UA']"
],
"name": "Block POST Requests With Large Content Length From Specific Countries"
},
{
"actions": [
{
"config": {
"status_code": 400
},
"type": "deny"
}
],
"expressions": [
"'ChatGPT' in req.Headers['User-Agent'] || 'GPTBot' in req.Headers['User-Agent']"
],
"name": "Block AI Crawler Bots"
}
],
"outbound": [
{
"actions": [
{
"config": {
"metadata": {
"edgeId": "edghts_2fKmctp7pQGnDcS5wMZ3EpALwAV",
"message": "Unsuccessful response",
"routeId": "edghtsrt_2fKmcqaUXNXC8riDf9GTOMcVB7T"
}
},
"type": "log"
}
],
"expressions": ["res.StatusCode < '200' || res.StatusCode > '300'"],
"name": "Log Unsuccessful Response"
}
]
}

Fields

NameTypeDescription
enabledbooleantrue if the module will be applied to traffic, false to disable. default true if unspecified
inboundEndpointRulethe inbound rules of the traffic policy.
outboundEndpointRulethe outbound rules on the traffic policy.

EndpointRule fields

NameTypeDescription
expressionsList<string>cel expressions that filter traffic the policy rule applies to.
actionsEndpointActionthe set of actions on a policy rule.
namestringthe name of the rule that is part of the traffic policy.

EndpointAction fields

NameTypeDescription
typestringthe type of action on the policy rule.
configobjectthe configuration for the action on the policy rule.

Delete HTTPS Edge Route Policies Module

Request

DELETE /edges/https/{edge_id}/routes/{id}/policy

Example Request

curl \
-X DELETE \
-H "Authorization: Bearer {API_KEY}" \
-H "Ngrok-Version: 2" \
https://api.ngrok.com/edges/https/edghts_2fKmctp7pQGnDcS5wMZ3EpALwAV/routes/edghtsrt_2fKmcqaUXNXC8riDf9GTOMcVB7T/policy

Response

Returns a 204 response with no body on success