Skip to content

Commit e59ec12

Browse files
authored
[Rules] Use APIRequest component in API examples (cloudflare#21215)
1 parent 4c3f89e commit e59ec12

File tree

16 files changed

+762
-802
lines changed

16 files changed

+762
-802
lines changed

src/content/docs/rules/cloud-connector/create-api.mdx

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ head:
88
content: Configure a Cloud Connector rule via API
99
---
1010

11+
import { APIRequest } from "~/components";
12+
1113
You can configure Cloud Connector rules using the [Cloudflare API](/fundamentals/api/).
1214

1315
## Required permissions
@@ -43,10 +45,7 @@ The following table summarizes the available operations.
4345

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

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

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

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

79-
```bash
80-
curl --request PUT \
81-
"https://api.cloudflare.com/client/v4/zones/{zone_id}/cloud_connector/rules" \
82-
--header "Authorization: Bearer <API_TOKEN>" \
83-
--header "Content-Type: application/json" \
84-
--data '[
85-
{
86-
"expression": "http.request.uri.path wildcard \"/images/*\"",
87-
"provider": "cloudflare_r2",
88-
"description": "Connect to R2 bucket containing images",
89-
"parameters": {
90-
"host": "mybucketcustomdomain.example.com"
91-
}
92-
}
93-
]'
94-
```
78+
<APIRequest
79+
path="/zones/{zone_id}/cloud_connector/rules"
80+
method="PUT"
81+
json={[
82+
{
83+
expression: 'http.request.uri.path wildcard "/images/*"',
84+
provider: "cloudflare_r2",
85+
description: "Connect to R2 bucket containing images",
86+
parameters: {
87+
host: "mybucketcustomdomain.example.com",
88+
},
89+
},
90+
]}
91+
/>
9592

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

src/content/docs/rules/compression-rules/examples/disable-all-brotli.mdx

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description: Create a compression rule to turn off Brotli compression for all
99
incoming requests of a given zone.
1010
---
1111

12-
import { Example, TabItem, Tabs } from "~/components";
12+
import { Example, TabItem, Tabs, APIRequest } from "~/components";
1313

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

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

3535
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:
3636

37-
```bash
38-
curl --request PUT \
39-
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
40-
--header "Authorization: Bearer <API_TOKEN>" \
41-
--header "Content-Type: application/json" \
42-
--data '{
43-
"rules": [
44-
{
45-
"expression": "true",
46-
"action": "compress_response",
47-
"action_parameters": {
48-
"algorithms": [
49-
{ "name": "gzip" }
50-
]
51-
}
52-
}
53-
]
54-
}'
55-
```
37+
<APIRequest
38+
path="/zones/{zone_id}/rulesets/{ruleset_id}"
39+
method="PUT"
40+
json={{
41+
rules: [
42+
{
43+
expression: "true",
44+
action: "compress_response",
45+
action_parameters: {
46+
algorithms: [{ name: "gzip" }],
47+
},
48+
},
49+
],
50+
}}
51+
/>
5652

5753
</TabItem> </Tabs>

src/content/docs/rules/compression-rules/examples/disable-compression-avif.mdx

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ description: Create a compression rule to turn off compression for AVIF images,
1111
request.
1212
---
1313

14-
import { Example, TabItem, Tabs } from "~/components";
14+
import { Example, TabItem, Tabs, APIRequest } from "~/components";
1515

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

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

3737
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:
3838

39-
```bash wrap
40-
curl --request PUT \
41-
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
42-
--header "Authorization: Bearer <API_TOKEN>" \
43-
--header "Content-Type: application/json" \
44-
--data '{
45-
"rules": [
46-
{
47-
"expression": "http.response.content_type.media_type eq \"image/avif\" or http.request.uri.path.extension eq \"avif\"",
48-
"action": "compress_response",
49-
"action_parameters": {
50-
"algorithms": [
51-
{ "name": "none" }
52-
]
53-
}
54-
}
55-
]
56-
}'
57-
```
39+
<APIRequest
40+
path="/zones/{zone_id}/rulesets/{ruleset_id}"
41+
method="PUT"
42+
json={{
43+
rules: [
44+
{
45+
expression:
46+
'http.response.content_type.media_type eq "image/avif" or http.request.uri.path.extension eq "avif"',
47+
action: "compress_response",
48+
action_parameters: {
49+
algorithms: [{ name: "none" }],
50+
},
51+
},
52+
],
53+
}}
54+
/>
5855

5956
</TabItem> </Tabs>

src/content/docs/rules/compression-rules/examples/enable-zstandard.mdx

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ title: Enable Zstandard compression for default content types
77
description: Create a compression rule to turn on Zstandard compression for response content types where Cloudflare applies compression by default.
88
---
99

10-
import { Example, TabItem, Tabs } from "~/components";
10+
import { Example, TabItem, Tabs, APIRequest } from "~/components";
1111

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

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

3333
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:
3434

35-
```bash wrap
36-
curl --request PUT \
37-
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
38-
--header "Authorization: Bearer <API_TOKEN>" \
39-
--header "Content-Type: application/json" \
40-
--data '{
41-
"rules": [
42-
{
43-
"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\"})",
44-
"action": "compress_response",
45-
"action_parameters": {
46-
"algorithms": [
47-
{ "name": "zstd" },
48-
{ "name": "brotli" },
49-
{ "name": "gzip" }
50-
]
51-
}
52-
}
53-
]
54-
}'
55-
```
35+
<APIRequest
36+
path="/zones/{zone_id}/rulesets/{ruleset_id}"
37+
method="PUT"
38+
json={{
39+
rules: [
40+
{
41+
expression:
42+
'(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"})',
43+
action: "compress_response",
44+
action_parameters: {
45+
algorithms: [{ name: "zstd" }, { name: "brotli" }, { name: "gzip" }],
46+
},
47+
},
48+
],
49+
}}
50+
/>
5651

5752
</TabItem> </Tabs>

src/content/docs/rules/compression-rules/examples/gzip-for-csv.mdx

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description: Create a compression rule to set Gzip compression as the preferred
99
compression method for CSV files.
1010
---
1111

12-
import { Example, TabItem, Tabs } from "~/components";
12+
import { Example, TabItem, Tabs, APIRequest } from "~/components";
1313

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

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

3535
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:
3636

37-
```bash
38-
curl --request PUT \
39-
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
40-
--header "Authorization: Bearer <API_TOKEN>" \
41-
--header "Content-Type: application/json" \
42-
--data '{
43-
"rules": [
44-
{
45-
"expression": "http.request.uri.path.extension eq \"csv\"",
46-
"action": "compress_response",
47-
"action_parameters": {
48-
"algorithms": [
49-
{ "name": "gzip" },
50-
{ "name": "auto" }
51-
]
52-
}
53-
}
54-
]
55-
}'
56-
```
37+
<APIRequest
38+
path="/zones/{zone_id}/rulesets/{ruleset_id}"
39+
method="PUT"
40+
json={{
41+
rules: [
42+
{
43+
expression: 'http.request.uri.path.extension eq "csv"',
44+
action: "compress_response",
45+
action_parameters: {
46+
algorithms: [{ name: "gzip" }, { name: "auto" }],
47+
},
48+
},
49+
],
50+
}}
51+
/>
5752

5853
</TabItem> </Tabs>

src/content/docs/rules/compression-rules/examples/only-brotli-url-path.mdx

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description: Create a compression rule to set Brotli as the only supported
99
compression algorithm for a specific URI path.
1010
---
1111

12-
import { Example, TabItem, Tabs } from "~/components";
12+
import { Example, TabItem, Tabs, APIRequest } from "~/components";
1313

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

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

3737
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:
3838

39-
```bash
40-
curl --request PUT \
41-
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
42-
--header "Authorization: Bearer <API_TOKEN>" \
43-
--header "Content-Type: application/json" \
44-
--data '{
45-
"rules": [
46-
{
47-
"expression": "http.request.uri.path eq \"/download/assets.tar\"",
48-
"action": "compress_response",
49-
"action_parameters": {
50-
"algorithms": [
51-
{ "name": "brotli" }
52-
]
53-
}
54-
}
55-
]
56-
}'
57-
```
39+
<APIRequest
40+
path="/zones/{zone_id}/rulesets/{ruleset_id}"
41+
method="PUT"
42+
json={{
43+
rules: [
44+
{
45+
expression: 'http.request.uri.path eq "/download/assets.tar"',
46+
action: "compress_response",
47+
action_parameters: {
48+
algorithms: [{ name: "brotli" }],
49+
},
50+
},
51+
],
52+
}}
53+
/>
5854

5955
</TabItem> </Tabs>

0 commit comments

Comments
 (0)