Skip to content

Commit e2281d3

Browse files
authored
[Rules] Use output blocks (#17599)
1 parent d34719f commit e2281d3

File tree

7 files changed

+657
-701
lines changed

7 files changed

+657
-701
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ curl https://api.cloudflare.com/client/v4/zones/{zone_id}/cloud_connector/rules
4848
--header "Authorization: Bearer <API_TOKEN>"
4949
```
5050

51-
```json title="Example response"
51+
```json output
5252
{
5353
"result": [
5454
{

src/content/docs/rules/origin-rules/create-api.mdx

Lines changed: 104 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,36 @@ sidebar:
66
head:
77
- tag: title
88
content: Create an origin rule via API
9-
109
---
1110

12-
import { Details, Render } from "~/components"
11+
import { Details, Render } from "~/components";
1312

1413
Use the [Rulesets API](/ruleset-engine/rulesets-api/) to create origin rules via API.
1514

1615
## Basic rule settings
1716

1817
When creating an origin rule via API, make sure you:
1918

20-
* Set the rule action to `route`.
21-
* Define the [parameters](/rules/origin-rules/parameters/) in the `action_parameters` field according to the type of origin override.
22-
* Deploy the rule to the `http_request_origin` phase at the zone level.
19+
- Set the rule action to `route`.
20+
- Define the [parameters](/rules/origin-rules/parameters/) in the `action_parameters` field according to the type of origin override.
21+
- Deploy the rule to the `http_request_origin` phase at the zone level.
2322

2423
## Procedure
2524

26-
<Render file="rules-creation-workflow" params={{ one: "an origin rule", two: "http_request_origin" }} />
25+
<Render
26+
file="rules-creation-workflow"
27+
params={{ one: "an origin rule", two: "http_request_origin" }}
28+
/>
2729

2830
Make sure your API token has the [required permissions](#required-api-token-permissions) to perform the API operations.
2931

3032
## Example requests
3133

32-
3334
<Details header="Example: Add a rule that overrides the HTTP `Host` header">
3435

35-
The following example sets the rules of an existing phase ruleset (`{ruleset_id}`) to a single origin rule — overriding the HTTP `Host` header — using the [Update a zone ruleset](/api/operations/updateZoneRuleset) operation:
36+
The following example sets the rules of an existing phase ruleset (`{ruleset_id}`) to a single origin rule — overriding the HTTP `Host` header — using the [Update a zone ruleset](/api/operations/updateZoneRuleset) operation. The response will contain the complete definition of the ruleset you updated.
3637

37-
```bash title="Request"
38+
```bash
3839
curl --request PUT \
3940
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
4041
--header "Authorization: Bearer <API_TOKEN>" \
@@ -53,48 +54,44 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
5354
}'
5455
```
5556

56-
The response contains the complete definition of the ruleset you updated.
57-
58-
```json title="Response"
57+
```json output
5958
{
60-
"result": {
61-
"id": "<RULESET_ID>",
62-
"name": "Origin Rules ruleset",
63-
"description": "Zone-level ruleset that will execute origin rules.",
64-
"kind": "zone",
65-
"version": "2",
66-
"rules": [
67-
{
68-
"id": "<RULE_ID>",
69-
"version": "1",
70-
"action": "route",
71-
"action_parameters": {
72-
"host_header": "eu_server.example.net"
73-
},
74-
"expression": "http.request.uri.query contains \"/eu/\"",
75-
"description": "My first origin rule",
76-
"last_updated": "2022-06-02T14:42:04.219025Z",
77-
"ref": "<RULE_REF>"
78-
}
79-
],
80-
"last_updated": "2022-06-02T14:42:04.219025Z",
81-
"phase": "http_request_origin"
82-
},
83-
"success": true,
84-
"errors": [],
85-
"messages": []
59+
"result": {
60+
"id": "<RULESET_ID>",
61+
"name": "Origin Rules ruleset",
62+
"description": "Zone-level ruleset that will execute origin rules.",
63+
"kind": "zone",
64+
"version": "2",
65+
"rules": [
66+
{
67+
"id": "<RULE_ID>",
68+
"version": "1",
69+
"action": "route",
70+
"action_parameters": {
71+
"host_header": "eu_server.example.net"
72+
},
73+
"expression": "http.request.uri.query contains \"/eu/\"",
74+
"description": "My first origin rule",
75+
"last_updated": "2022-06-02T14:42:04.219025Z",
76+
"ref": "<RULE_REF>"
77+
}
78+
],
79+
"last_updated": "2022-06-02T14:42:04.219025Z",
80+
"phase": "http_request_origin"
81+
},
82+
"success": true,
83+
"errors": [],
84+
"messages": []
8685
}
8786
```
8887

89-
9088
</Details>
9189

92-
9390
<Details header="Example: Add a rule that overrides the SNI value of incoming requests">
9491

95-
The following example sets the rules of an existing phase ruleset (`{ruleset_id}`) to a single origin rule — overriding the SNI value of incoming requests addressed at `admin.example.com` — using the [Update a zone ruleset](/api/operations/updateZoneRuleset) operation:
92+
The following example sets the rules of an existing phase ruleset (`{ruleset_id}`) to a single origin rule — overriding the SNI value of incoming requests addressed at `admin.example.com` — using the [Update a zone ruleset](/api/operations/updateZoneRuleset) operation.
9693

97-
```bash title="Request"
94+
```bash
9895
curl --request PUT \
9996
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
10097
--header "Authorization: Bearer <API_TOKEN>" \
@@ -115,15 +112,13 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
115112
}'
116113
```
117114

118-
119115
</Details>
120116

121-
122117
<Details header="Example: Add a rule that overrides the resolved DNS record and the `Host` header of incoming requests">
123118

124-
The following example sets the rules of an existing phase ruleset (`{ruleset_id}`) to a single origin rule — overriding the resolved DNS record and the `Host` header of incoming requests — using the [Update a zone ruleset](/api/operations/updateZoneRuleset) operation:
119+
The following example sets the rules of an existing phase ruleset (`{ruleset_id}`) to a single origin rule — overriding the resolved DNS record and the `Host` header of incoming requests — using the [Update a zone ruleset](/api/operations/updateZoneRuleset) operation. The response will contain the complete definition of the ruleset you updated.
125120

126-
```bash title="Request"
121+
```bash
127122
curl --request PUT \
128123
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
129124
--header "Authorization: Bearer <API_TOKEN>" \
@@ -145,51 +140,47 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
145140
}'
146141
```
147142

148-
The response contains the complete definition of the ruleset you updated.
149-
150-
```json title="Response"
143+
```json output
151144
{
152-
"result": {
153-
"id": "<RULESET_ID>",
154-
"name": "Origin Rules ruleset",
155-
"description": "Zone-level ruleset that will execute origin rules.",
156-
"kind": "zone",
157-
"version": "2",
158-
"rules": [
159-
{
160-
"id": "<RULE_ID>",
161-
"version": "1",
162-
"action": "route",
163-
"action_parameters": {
164-
"host_header": "hr-server.example.com",
165-
"origin": {
166-
"host": "hr-server.example.com"
167-
}
168-
},
169-
"expression": "starts_with(http.request.uri.path, \"/hr-app/\")",
170-
"description": "Origin rule for the company HR application",
171-
"last_updated": "2022-06-03T14:42:04.219025Z",
172-
"ref": "<RULE_REF>"
173-
}
174-
],
175-
"last_updated": "2022-06-03T14:42:04.219025Z",
176-
"phase": "http_request_origin"
177-
},
178-
"success": true,
179-
"errors": [],
180-
"messages": []
145+
"result": {
146+
"id": "<RULESET_ID>",
147+
"name": "Origin Rules ruleset",
148+
"description": "Zone-level ruleset that will execute origin rules.",
149+
"kind": "zone",
150+
"version": "2",
151+
"rules": [
152+
{
153+
"id": "<RULE_ID>",
154+
"version": "1",
155+
"action": "route",
156+
"action_parameters": {
157+
"host_header": "hr-server.example.com",
158+
"origin": {
159+
"host": "hr-server.example.com"
160+
}
161+
},
162+
"expression": "starts_with(http.request.uri.path, \"/hr-app/\")",
163+
"description": "Origin rule for the company HR application",
164+
"last_updated": "2022-06-03T14:42:04.219025Z",
165+
"ref": "<RULE_REF>"
166+
}
167+
],
168+
"last_updated": "2022-06-03T14:42:04.219025Z",
169+
"phase": "http_request_origin"
170+
},
171+
"success": true,
172+
"errors": [],
173+
"messages": []
181174
}
182175
```
183176

184-
185177
</Details>
186178

187-
188179
<Details header="Example: Add a rule that overrides the port of incoming requests">
189180

190-
The following example sets the rules of an existing phase ruleset (`{ruleset_id}`) to a single origin rule — overriding the port of incoming requests — using the [Update a zone ruleset](/api/operations/updateZoneRuleset) operation:
181+
The following example sets the rules of an existing phase ruleset (`{ruleset_id}`) to a single origin rule — overriding the port of incoming requests — using the [Update a zone ruleset](/api/operations/updateZoneRuleset) operation. The response will contain the complete definition of the ruleset you updated.
191182

192-
```bash title="Request"
183+
```bash
193184
curl --request PUT \
194185
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
195186
--header "Authorization: Bearer <API_TOKEN>" \
@@ -210,48 +201,45 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
210201
}'
211202
```
212203

213-
The response contains the complete definition of the ruleset you updated.
214-
215-
```json title="Response"
204+
```json output
216205
{
217-
"result": {
218-
"id": "<RULESET_ID>",
219-
"name": "Origin Rules ruleset",
220-
"description": "Zone-level ruleset that will execute origin rules.",
221-
"kind": "zone",
222-
"version": "2",
223-
"rules": [
224-
{
225-
"id": "<RULE_ID>",
226-
"version": "1",
227-
"action": "route",
228-
"action_parameters": {
229-
"origin": {
230-
"port": 9000
231-
}
232-
},
233-
"expression": "starts_with(http.request.uri.path, \"/team/calendar/\")",
234-
"description": "Origin rule for the team calendar application",
235-
"last_updated": "2022-06-03T14:42:04.219025Z",
236-
"ref": "<RULE_REF>"
237-
}
238-
],
239-
"last_updated": "2022-06-03T14:42:04.219025Z",
240-
"phase": "http_request_origin"
241-
},
242-
"success": true,
243-
"errors": [],
244-
"messages": []
206+
"result": {
207+
"id": "<RULESET_ID>",
208+
"name": "Origin Rules ruleset",
209+
"description": "Zone-level ruleset that will execute origin rules.",
210+
"kind": "zone",
211+
"version": "2",
212+
"rules": [
213+
{
214+
"id": "<RULE_ID>",
215+
"version": "1",
216+
"action": "route",
217+
"action_parameters": {
218+
"origin": {
219+
"port": 9000
220+
}
221+
},
222+
"expression": "starts_with(http.request.uri.path, \"/team/calendar/\")",
223+
"description": "Origin rule for the team calendar application",
224+
"last_updated": "2022-06-03T14:42:04.219025Z",
225+
"ref": "<RULE_REF>"
226+
}
227+
],
228+
"last_updated": "2022-06-03T14:42:04.219025Z",
229+
"phase": "http_request_origin"
230+
},
231+
"success": true,
232+
"errors": [],
233+
"messages": []
245234
}
246235
```
247236

248-
249237
</Details>
250238

251-
***
239+
---
252240

253241
## Required API token permissions
254242

255243
The API token used in API requests to manage origin rules must have at least the following permission:
256244

257-
* *Origin* > *Edit*
245+
- _Origin_ > _Edit_

0 commit comments

Comments
 (0)