Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Rules] Use APIRequest component in API examples #21215

Open
wants to merge 9 commits into
base: production
Choose a base branch
from
37 changes: 17 additions & 20 deletions src/content/docs/rules/cloud-connector/create-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ head:
content: Configure a Cloud Connector rule via API
---

import { APIRequest } from "~/components";

You can configure Cloud Connector rules using the [Cloudflare API](/fundamentals/api/).

## Required permissions
Expand Down Expand Up @@ -43,10 +45,7 @@ The following table summarizes the available operations.

The following example returns a list of existing Cloud Connector rules:

```bash
curl https://api.cloudflare.com/client/v4/zones/{zone_id}/cloud_connector/rules \
--header "Authorization: Bearer <API_TOKEN>"
```
<APIRequest path="/zones/{zone_id}/cloud_connector/rules" method="GET" />

```json output
{
Expand Down Expand Up @@ -76,22 +75,20 @@ To create a new rule and keep all existing rules, you must include them all in y

The following example request will replace all existing Cloud Connector rules with a single rule:

```bash
curl --request PUT \
"https://api.cloudflare.com/client/v4/zones/{zone_id}/cloud_connector/rules" \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '[
{
"expression": "http.request.uri.path wildcard \"/images/*\"",
"provider": "cloudflare_r2",
"description": "Connect to R2 bucket containing images",
"parameters": {
"host": "mybucketcustomdomain.example.com"
}
}
]'
```
<APIRequest
path="/zones/{zone_id}/cloud_connector/rules"
method="PUT"
json={[
{
expression: 'http.request.uri.path wildcard "/images/*"',
provider: "cloudflare_r2",
description: "Connect to R2 bucket containing images",
parameters: {
host: "mybucketcustomdomain.example.com",
},
},
]}
/>

The required body parameters for each rule are: `expression`, `provider`, and `parameters.host`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description: Create a compression rule to turn off Brotli compression for all
incoming requests of a given zone.
---

import { Example, TabItem, Tabs } from "~/components";
import { Example, TabItem, Tabs, APIRequest } from "~/components";

<Tabs syncKey="dashPlusAPI"> <TabItem label="Dashboard">

Expand All @@ -34,24 +34,20 @@ If the client does not support Gzip compression, the response will be uncompress

The following example sets the rules of an existing [entry point ruleset](/ruleset-engine/about/rulesets/#entry-point-ruleset) (with ID `{ruleset_id}`) for the `http_response_compression` phase to a single compression rule, using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation:

```bash
curl --request PUT \
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{
"rules": [
{
"expression": "true",
"action": "compress_response",
"action_parameters": {
"algorithms": [
{ "name": "gzip" }
]
}
}
]
}'
```
<APIRequest
path="/zones/{zone_id}/rulesets/{ruleset_id}"
method="PUT"
json={{
rules: [
{
expression: "true",
action: "compress_response",
action_parameters: {
algorithms: [{ name: "gzip" }],
},
},
],
}}
/>

</TabItem> </Tabs>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: Create a compression rule to turn off compression for AVIF images,
request.
---

import { Example, TabItem, Tabs } from "~/components";
import { Example, TabItem, Tabs, APIRequest } from "~/components";

<Tabs syncKey="dashPlusAPI"> <TabItem label="Dashboard">

Expand All @@ -36,24 +36,21 @@ The following example rule will disable compression for AVIF images, based on ei

The following example sets the rules of an existing [entry point ruleset](/ruleset-engine/about/rulesets/#entry-point-ruleset) (with ID `{ruleset_id}`) for the `http_response_compression` phase to a single compression rule, using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation:

```bash wrap
curl --request PUT \
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{
"rules": [
{
"expression": "http.response.content_type.media_type eq \"image/avif\" or http.request.uri.path.extension eq \"avif\"",
"action": "compress_response",
"action_parameters": {
"algorithms": [
{ "name": "none" }
]
}
}
]
}'
```
<APIRequest
path="/zones/{zone_id}/rulesets/{ruleset_id}"
method="PUT"
json={{
rules: [
{
expression:
'http.response.content_type.media_type eq "image/avif" or http.request.uri.path.extension eq "avif"',
action: "compress_response",
action_parameters: {
algorithms: [{ name: "none" }],
},
},
],
}}
/>

</TabItem> </Tabs>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ title: Enable Zstandard compression for default content types
description: Create a compression rule to turn on Zstandard compression for response content types where Cloudflare applies compression by default.
---

import { Example, TabItem, Tabs } from "~/components";
import { Example, TabItem, Tabs, APIRequest } from "~/components";

<Tabs syncKey="dashPlusAPI"> <TabItem label="Dashboard">

Expand All @@ -32,26 +32,21 @@ The following example rule will turn on Zstandard compression for response conte

The following example sets the rules of an existing [entry point ruleset](/ruleset-engine/about/rulesets/#entry-point-ruleset) (with ID `{ruleset_id}`) for the `http_response_compression` phase to a single compression rule, using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation:

```bash wrap
curl --request PUT \
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{
"rules": [
{
"expression": "(http.response.content_type.media_type in {\"text/html\" \"text/richtext\" \"text/plain\" \"text/css\" \"text/x-script\" \"text/x-component\" \"text/x-java-source\" \"text/x-markdown\" \"application/javascript\" \"application/x-javascript\" \"text/javascript\" \"text/js\" \"image/x-icon\" \"image/vnd.microsoft.icon\" \"application/x-perl\" \"application/x-httpd-cgi\" \"text/xml\" \"application/xml\" \"application/rss+xml\" \"application/vnd.api+json\" \"application/x-protobuf\" \"application/json\" \"multipart/bag\" \"multipart/mixed\" \"application/xhtml+xml\" \"font/ttf\" \"font/otf\" \"font/x-woff\" \"image/svg+xml\" \"application/vnd.ms-fontobject\" \"application/ttf\" \"application/x-ttf\" \"application/otf\" \"application/x-otf\" \"application/truetype\" \"application/opentype\" \"application/x-opentype\" \"application/font-woff\" \"application/eot\" \"application/font\" \"application/font-sfnt\" \"application/wasm\" \"application/javascript-binast\" \"application/manifest+json\" \"application/ld+json\" \"application/graphql+json\" \"application/geo+json\"})",
"action": "compress_response",
"action_parameters": {
"algorithms": [
{ "name": "zstd" },
{ "name": "brotli" },
{ "name": "gzip" }
]
}
}
]
}'
```
<APIRequest
path="/zones/{zone_id}/rulesets/{ruleset_id}"
method="PUT"
json={{
rules: [
{
expression:
'(http.response.content_type.media_type in {"text/html" "text/richtext" "text/plain" "text/css" "text/x-script" "text/x-component" "text/x-java-source" "text/x-markdown" "application/javascript" "application/x-javascript" "text/javascript" "text/js" "image/x-icon" "image/vnd.microsoft.icon" "application/x-perl" "application/x-httpd-cgi" "text/xml" "application/xml" "application/rss+xml" "application/vnd.api+json" "application/x-protobuf" "application/json" "multipart/bag" "multipart/mixed" "application/xhtml+xml" "font/ttf" "font/otf" "font/x-woff" "image/svg+xml" "application/vnd.ms-fontobject" "application/ttf" "application/x-ttf" "application/otf" "application/x-otf" "application/truetype" "application/opentype" "application/x-opentype" "application/font-woff" "application/eot" "application/font" "application/font-sfnt" "application/wasm" "application/javascript-binast" "application/manifest+json" "application/ld+json" "application/graphql+json" "application/geo+json"})',
action: "compress_response",
action_parameters: {
algorithms: [{ name: "zstd" }, { name: "brotli" }, { name: "gzip" }],
},
},
],
}}
/>

</TabItem> </Tabs>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description: Create a compression rule to set Gzip compression as the preferred
compression method for CSV files.
---

import { Example, TabItem, Tabs } from "~/components";
import { Example, TabItem, Tabs, APIRequest } from "~/components";

<Tabs syncKey="dashPlusAPI"> <TabItem label="Dashboard">

Expand All @@ -34,25 +34,20 @@ The following example rule will configure Gzip compression as the preferred comp

The following example sets the rules of an existing [entry point ruleset](/ruleset-engine/about/rulesets/#entry-point-ruleset) (with ID `{ruleset_id}`) for the `http_response_compression` phase to a single compression rule, using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation:

```bash
curl --request PUT \
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{
"rules": [
{
"expression": "http.request.uri.path.extension eq \"csv\"",
"action": "compress_response",
"action_parameters": {
"algorithms": [
{ "name": "gzip" },
{ "name": "auto" }
]
}
}
]
}'
```
<APIRequest
path="/zones/{zone_id}/rulesets/{ruleset_id}"
method="PUT"
json={{
rules: [
{
expression: 'http.request.uri.path.extension eq "csv"',
action: "compress_response",
action_parameters: {
algorithms: [{ name: "gzip" }, { name: "auto" }],
},
},
],
}}
/>

</TabItem> </Tabs>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description: Create a compression rule to set Brotli as the only supported
compression algorithm for a specific URI path.
---

import { Example, TabItem, Tabs } from "~/components";
import { Example, TabItem, Tabs, APIRequest } from "~/components";

<Tabs syncKey="dashPlusAPI"> <TabItem label="Dashboard">

Expand All @@ -36,24 +36,20 @@ Since the rule configuration does not include _Auto_ at the end of the custom al

The following example sets the rules of an existing [entry point ruleset](/ruleset-engine/about/rulesets/#entry-point-ruleset) (with ID `{ruleset_id}`) for the `http_response_compression` phase to a single compression rule, using the [Update a zone ruleset](/api/resources/rulesets/methods/update/) operation:

```bash
curl --request PUT \
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{
"rules": [
{
"expression": "http.request.uri.path eq \"/download/assets.tar\"",
"action": "compress_response",
"action_parameters": {
"algorithms": [
{ "name": "brotli" }
]
}
}
]
}'
```
<APIRequest
path="/zones/{zone_id}/rulesets/{ruleset_id}"
method="PUT"
json={{
rules: [
{
expression: 'http.request.uri.path eq "/download/assets.tar"',
action: "compress_response",
action_parameters: {
algorithms: [{ name: "brotli" }],
},
},
],
}}
/>

</TabItem> </Tabs>
Loading