Cloudflare Docs
Rules
Rules
Visit Rules on GitHub
Set theme to dark (⇧+D)

Create a compression rule via API

Use the Rulesets API to create a compression rule via API.

When creating a compression rule via API, make sure you:

  • Set the rule action to compress_response.
  • Define the parameters in the action_parameters field according to the settings you wish to override for matching requests.
  • Deploy the rule to the http_response_compression phase at the zone level.

Follow this workflow to create a compression rule for a given zone via API:

  1. Use the List existing rulesets method to check if there is already a ruleset for the http_response_compression phase at the zone level.

  2. If the phase ruleset does not exist, create it using the Create ruleset method with the zone-level endpoint. In the new ruleset properties, set the following values:

    • kind: zone
    • phase: http_response_compression
  3. Use the Update ruleset method to add a compression rule to the list of ruleset rules (check the examples below). Alternatively, include the rule in the Create ruleset request mentioned in the previous step.

​​ Examples

Refer to the Examples page for example API requests.