Skip to content

Commit 30666bd

Browse files
angelampcostasdnts
authored andcommitted
Adds APIRequest component to Cache rules examples (cloudflare#23582)
1 parent d49a5d9 commit 30666bd

File tree

1 file changed

+87
-95
lines changed

1 file changed

+87
-95
lines changed

src/content/docs/cache/how-to/cache-rules/create-api.mdx

Lines changed: 87 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ head:
1010

1111
---
1212

13-
import { Details } from "~/components"
13+
import { Details, APIRequest } from "~/components"
1414

1515
Use the [Rulesets API](https://developers.cloudflare.com/ruleset-engine/rulesets-api/) to create a cache rule via API. To configure Cloudflare’s API refer to the [API documentation](/fundamentals/api/get-started/).
1616

@@ -38,131 +38,123 @@ These examples are setting all the Cache Rules of a zone to a single rule, since
3838

3939
<Details header="Example: Cache everything for example.com">
4040

41-
```bash title="Request"
42-
curl --request PUT \
43-
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
44-
--header "Authorization: Bearer <API_TOKEN>" \
45-
--header "Content-Type: application/json" \
46-
--data '{
47-
"rules": [
48-
{
49-
"expression": "(http.host eq \"example.com\")",
50-
"description": "cache everything for example.com",
51-
"action": "set_cache_settings",
52-
"action_parameters": {
53-
"cache": true
41+
<APIRequest
42+
path="/zones/{zone_id}/rulesets/{ruleset_id}"
43+
method="PUT"
44+
json={{
45+
rules: [
46+
{
47+
expression: '(http.host eq "example.com")',
48+
description: "cache everything for example.com",
49+
action: "set_cache_settings",
50+
action_parameters: {
51+
cache: true
52+
}
5453
}
55-
}
56-
]
57-
}'
58-
```
54+
]
55+
}}
56+
roles={false}
57+
/>
5958

6059

6160
</Details>
6261

6362

6463
<Details header="Example: Extend read timeout for Android clients">
6564

66-
```bash title="Request"
67-
curl --request PUT \
68-
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
69-
--header "Authorization: Bearer <API_TOKEN>" \
70-
--header "Content-Type: application/json" \
71-
--data '{
72-
"rules": [
73-
{
74-
"expression": "(http.user_agent contains \"Android\")",
75-
"description": "extend read timeout for android clients",
76-
"action": "set_cache_settings",
77-
"action_parameters": {
78-
"cache": true,
79-
"read_timeout": 300
65+
<APIRequest
66+
path="/zones/{zone_id}/rulesets/{ruleset_id}"
67+
method="PUT"
68+
json={{
69+
rules: [
70+
{
71+
expression: '(http.user_agent contains "Android")',
72+
description: "extend read timeout for android clients",
73+
action: "set_cache_settings",
74+
action_parameters: {
75+
cache: true,
76+
read_timeout: 300
77+
}
8078
}
81-
}
82-
]
83-
}'
84-
```
85-
79+
]
80+
}}
81+
roles={false}
82+
/>
8683

8784
</Details>
8885

8986

9087
<Details header="Example: Disable Cache Reserve for frequently updated assets">
9188

92-
```bash title="Request"
93-
curl --request PUT \
94-
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
95-
--header "Authorization: Bearer <API_TOKEN>" \
96-
--header "Content-Type: application/json" \
97-
--data '{
98-
"rules": [
99-
{
100-
"expression": "(starts_with(http.request.uri, \"/feed/\"))",
101-
"description": "disable cache reserve for frequently updated assets",
102-
"action": "set_cache_settings",
103-
"action_parameters": {
104-
"cache": true,
105-
"cache_reserve": {
106-
"enabled": false
89+
<APIRequest
90+
path="/zones/{zone_id}/rulesets/{ruleset_id}"
91+
method="PUT"
92+
json={{
93+
rules: [
94+
{
95+
expression: '(starts_with(http.request.uri, "/feed/"))',
96+
description: "disable cache reserve for frequently updated assets",
97+
action: "set_cache_settings",
98+
action_parameters: {
99+
cache: true,
100+
cache_reserve: {
101+
enabled: false
102+
}
107103
}
108104
}
109-
}
110-
]
111-
}'
112-
```
113-
105+
]
106+
}}
107+
roles={false}
108+
/>
114109

115110
</Details>
116111

117112

118113
<Details header="Example: Turn off default cache TTLs">
119114

120-
```bash title="Request"
121-
curl --request PUT \
122-
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
123-
--header "Authorization: Bearer <API_TOKEN>" \
124-
--header "Content-Type: application/json" \
125-
--data '{
126-
"rules": [
127-
{
128-
"expression": "(http.host eq \"example.com\")",
129-
"description": "turn off default cache ttls",
130-
"action": "set_cache_settings",
131-
"action_parameters": {
132-
"cache": true,
133-
"edge_ttl": {
134-
"mode": "bypass_by_default"
115+
<APIRequest
116+
path="/zones/{zone_id}/rulesets/{ruleset_id}"
117+
method="PUT"
118+
json={{
119+
rules: [
120+
{
121+
expression: '(http.host eq "example.com")',
122+
description: "turn off default cache ttls",
123+
action: "set_cache_settings",
124+
action_parameters: {
125+
cache: true,
126+
edge_ttl: {
127+
mode: "bypass_by_default"
128+
}
135129
}
136130
}
137-
}
138-
]
139-
}'
140-
```
141-
131+
]
132+
}}
133+
roles={false}
134+
/>
142135

143136
</Details>
144137

145138

146139
<Details header="Example: Update the position of an existing rule">
147140

148-
```bash title="Request"
149-
curl --request PATCH \
150-
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id}/rules/{rule_id} \
151-
--header "Authorization: Bearer <API_TOKEN>" \
152-
--header "Content-Type: application/json" \
153-
--data '{
154-
"expression": "(http.host eq \"example.com\")",
155-
"description": "cache everything for example.com",
156-
"action": "set_cache_settings",
157-
"action_parameters": {
158-
"cache": true
159-
}
160-
"enabled": true,
161-
"position": {
162-
"before": "da5e8e506c8e7877fe06cdf4c41add54"
163-
}
164-
}'
165-
```
141+
<APIRequest
142+
path="/zones/{zone_id}/rulesets/{ruleset_id}/rules/{rule_id}"
143+
method="PATCH"
144+
json={{
145+
expression: '(http.host eq "example.com")',
146+
description: "cache everything for example.com",
147+
action: "set_cache_settings",
148+
action_parameters: {
149+
cache: true
150+
},
151+
enabled: true,
152+
position: {
153+
before: "da5e8e506c8e7877fe06cdf4c41add54"
154+
}
155+
}}
156+
roles={false}
157+
/>
166158

167159

168160
</Details>

0 commit comments

Comments
 (0)