Create a compression rule via API

Last updated Apr 16, 2026 Use the Rulesets API to create a compression rule via API.

Basic rule settings

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.

Procedure

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

  1. Use the List zone rulesets operation 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 a zone ruleset operation. In the new ruleset properties, set the following values:
  3. kind: zone
  4. phase: http_response_compression
  5. Use the Update a zone ruleset operation to add a compression rule to the list of ruleset rules. Alternatively, include the rule in the Create a zone ruleset request mentioned in the previous step.

Examples

For example API requests, refer to the Examples gallery.

Was this helpful?

YesNo

On this page

Create a compression rule via API - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/rules/compression-rules/create-api/#page","headline":"Create a compression rule via API","description":"Create compression rules using the Rulesets API.","url":"https://developers.cloudflare.com/rules/compression-rules/create-api/","inLanguage":"en","image":"https://developers.cloudflare.com/rules/compression-rules/create-api/og.png?v=7118ec11dc2f2548","dateModified":"2026-04-16","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}


description: Create compression rules in the Cloudflare dashboard. title: Create a compression rule in the dashboard image: https://developers.cloudflare.com/rules/compression-rules/create-dashboard/og.png?v=304d14ecfc833097


Skip to content

Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/rules/llms.txt
Use this file to discover all available pages before exploring further.