Skip to main content

Edge Route Traffic Policy Module

Replace HTTPS Edge Route Traffic Policy Module

Request

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

Example Request

curl \
-X PUT \
-H "Authorization: Bearer {API_KEY}" \
-H "Content-Type: application/json" \
-H "Ngrok-Version: 2" \
-d '{"enabled":true,"value":"{\n\t\"inbound\":[\n\t\t{\n\t\t\t\"name\":\"Rewrite /products API Calls\",\n\t\t\t\"expressions\":[\"req.url.path == '/products'\"],\n\t\t\t\"actions\":[\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"url-rewrite\",\n\t\t\t\t\t\"config\": {\n\t\t\t\t\t\t\"from\": \"/products/?([.*]+)?\",\n\t\t\t\t\t\t\"to\": \"/products.php?query=$1\"\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\t\"name\":\"Block POST Requests With Large Content Length From Specific Countries\",\n\t\t\t\"expressions\":[\n\t\t\t\t\"req.method == 'POST' && req.content_length > 10000\",\n\t\t\t\t\"conn.geo.country_code in ['BR', 'CN', 'CU', 'IR', 'NG', 'RO', 'RU', 'SD', 'SY', 'UA']\"\n\t\t\t],\n\t\t\t\"actions\":[\n\t\t\t\t{\n\t\t\t\t\t\"type\":\"custom-response\",\n\t\t\t\t\t\"config\":{\n\t\t\t\t\t\t\"status_code\":401,\n\t\t\t\t\t\t\"headers\":{\n\t\t\t\t\t\t\t\"content-type\":\"text/plain\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"content\":\"access denied\"\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\t\"name\":\"Block AI Crawler Bots\",\n\t\t\t\"expressions\":[\"'ChatGPT' in req.headers['user-agent'] || 'GPTBot' in req.headers['user-agent']\"],\n\t\t\t\"actions\":[\n\t\t\t\t{\n\t\t\t\t\t\"type\":\"deny\",\n\t\t\t\t\t\"config\":{\n\t\t\t\t\t\t\"status_code\":400\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t}\n\t],\n\t\"outbound\":[\n\t\t{\n\t\t\t\"name\":\"Brotli Compress Responses\",\n\t\t\t\"actions\":[\n\t\t\t\t{\n\t\t\t\t\t\"type\":\"compress-response\",\n\t\t\t\t\t\"config\": {\n\t\t\t\t\t\t\"algorithms\":[\"br\"]\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t}\n\t]\n}"}' \
https://api.ngrok.com/edges/https/edghts_2k5okXODqRdNJwQ2MvGiWN5AKwK/routes/edghtsrt_2k5okXwpQWUewchiTyc6ZWyVeSo/traffic_policy

Parameters

NameTypeDescription
enabledbooleantrue if the module will be applied to traffic, false to disable. default true if unspecified
valuestringthe traffic policy that should be applied to the traffic on your endpoint.

Response

Returns a 200 response on success

Example Response

{
"enabled": true,
"value": "{\"inbound\":[{\"expressions\":[\"req.url.path == '/products'\"],\"name\":\"Rewrite /products API Calls\",\"actions\":[{\"type\":\"url-rewrite\",\"config\":{\"from\":\"/products/?([.*]+)?\",\"to\":\"/products.php?query=$1\"}}]},{\"expressions\":[\"req.method == 'POST' \\u0026\\u0026 req.content_length \\u003e 10000\",\"conn.geo.country_code in ['BR', 'CN', 'CU', 'IR', 'NG', 'RO', 'RU', 'SD', 'SY', 'UA']\"],\"name\":\"Block POST Requests With Large Content Length From Specific Countries\",\"actions\":[{\"type\":\"custom-response\",\"config\":{\"status_code\":401,\"headers\":{\"content-type\":\"text/plain\"},\"content\":\"access denied\"}}]},{\"expressions\":[\"'ChatGPT' in req.headers['user-agent'] || 'GPTBot' in req.headers['user-agent']\"],\"name\":\"Block AI Crawler Bots\",\"actions\":[{\"type\":\"deny\",\"config\":{\"status_code\":400}}]}],\"outbound\":[{\"name\":\"Brotli Compress Responses\",\"actions\":[{\"type\":\"compress-response\",\"config\":{\"algorithms\":[\"br\"]}}]}]}"
}

Fields

NameTypeDescription
enabledbooleantrue if the module will be applied to traffic, false to disable. default true if unspecified
valuestringthe traffic policy that should be applied to the traffic on your endpoint.

Get HTTPS Edge Route Traffic Policy Module

Request

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

Example Request

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

Response

Returns a 200 response on success

Example Response

{
"enabled": true,
"value": "{\"inbound\":[{\"expressions\":[\"req.url.path == '/products'\"],\"name\":\"Rewrite /products API Calls\",\"actions\":[{\"type\":\"url-rewrite\",\"config\":{\"from\":\"/products/?([.*]+)?\",\"to\":\"/products.php?query=$1\"}}]},{\"expressions\":[\"req.method == 'POST' \\u0026\\u0026 req.content_length \\u003e 10000\",\"conn.geo.country_code in ['BR', 'CN', 'CU', 'IR', 'NG', 'RO', 'RU', 'SD', 'SY', 'UA']\"],\"name\":\"Block POST Requests With Large Content Length From Specific Countries\",\"actions\":[{\"type\":\"custom-response\",\"config\":{\"status_code\":401,\"headers\":{\"content-type\":\"text/plain\"},\"content\":\"access denied\"}}]},{\"expressions\":[\"'ChatGPT' in req.headers['user-agent'] || 'GPTBot' in req.headers['user-agent']\"],\"name\":\"Block AI Crawler Bots\",\"actions\":[{\"type\":\"deny\",\"config\":{\"status_code\":400}}]}],\"outbound\":[{\"name\":\"Brotli Compress Responses\",\"actions\":[{\"type\":\"compress-response\",\"config\":{\"algorithms\":[\"br\"]}}]}]}"
}

Fields

NameTypeDescription
enabledbooleantrue if the module will be applied to traffic, false to disable. default true if unspecified
valuestringthe traffic policy that should be applied to the traffic on your endpoint.

Delete HTTPS Edge Route Traffic Policy Module

Request

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

Example Request

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

Response

Returns a 204 response with no body on success