|
10 | 10 |
|
11 | 11 | --- |
12 | 12 |
|
13 | | -import { Details } from "~/components" |
| 13 | +import { Details, APIRequest } from "~/components" |
14 | 14 |
|
15 | 15 | 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/). |
16 | 16 |
|
@@ -38,131 +38,123 @@ These examples are setting all the Cache Rules of a zone to a single rule, since |
38 | 38 |
|
39 | 39 | <Details header="Example: Cache everything for example.com"> |
40 | 40 |
|
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 | + } |
54 | 53 | } |
55 | | - } |
56 | | - ] |
57 | | -}' |
58 | | -``` |
| 54 | + ] |
| 55 | + }} |
| 56 | + roles={false} |
| 57 | +/> |
59 | 58 |
|
60 | 59 |
|
61 | 60 | </Details> |
62 | 61 |
|
63 | 62 |
|
64 | 63 | <Details header="Example: Extend read timeout for Android clients"> |
65 | 64 |
|
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 | + } |
80 | 78 | } |
81 | | - } |
82 | | - ] |
83 | | -}' |
84 | | -``` |
85 | | - |
| 79 | + ] |
| 80 | + }} |
| 81 | + roles={false} |
| 82 | +/> |
86 | 83 |
|
87 | 84 | </Details> |
88 | 85 |
|
89 | 86 |
|
90 | 87 | <Details header="Example: Disable Cache Reserve for frequently updated assets"> |
91 | 88 |
|
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 | + } |
107 | 103 | } |
108 | 104 | } |
109 | | - } |
110 | | - ] |
111 | | -}' |
112 | | -``` |
113 | | - |
| 105 | + ] |
| 106 | + }} |
| 107 | + roles={false} |
| 108 | +/> |
114 | 109 |
|
115 | 110 | </Details> |
116 | 111 |
|
117 | 112 |
|
118 | 113 | <Details header="Example: Turn off default cache TTLs"> |
119 | 114 |
|
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 | + } |
135 | 129 | } |
136 | 130 | } |
137 | | - } |
138 | | - ] |
139 | | -}' |
140 | | -``` |
141 | | - |
| 131 | + ] |
| 132 | + }} |
| 133 | + roles={false} |
| 134 | +/> |
142 | 135 |
|
143 | 136 | </Details> |
144 | 137 |
|
145 | 138 |
|
146 | 139 | <Details header="Example: Update the position of an existing rule"> |
147 | 140 |
|
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 | +/> |
166 | 158 |
|
167 | 159 |
|
168 | 160 | </Details> |
|
0 commit comments