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

[Style guide] API placeholder guidelines #19387

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sidebar:

---

Use long parameter names, like in the [API reference documentation](/api/), for clarity:
Use long parameter names for clarity:

* `--header` (instead of `-H`)
* `--request` (when needed, instead of `-X`)
Expand All @@ -33,7 +33,7 @@ If you must suggest the use of this tool, you can add a link to the [Make API ca
### Preliminary notes

* Make sure not to use typographical or smart quotes in a cURL command, or the command will fail.
* Placeholders in the URL should follow the same format as in the API documentation: `{zone_id}`
* Placeholders in the URL should follow the same format as in the API documentation: `$ZONE_ID`
* Placeholders in the request body (that is, the data included in a `POST`/`PUT`/`PATCH` request) should use this format: `<RULE_ID>`

The same placeholder name should correspond to the same value – use different placeholder names for different ID values. You can use the same request placeholders in the response, if they should match the values in the request.
Expand All @@ -43,19 +43,19 @@ The same placeholder name should correspond to the same value – use different
If using Email + API Key authentication, include the following arguments in the cURL command to add the two required HTTP headers to the request:

```txt
--header "X-Auth-Email: <EMAIL>" \
--header "X-Auth-Key: <API_KEY>" \
--header "X-Auth-Email: $CLOUDFLARE_EMAIL" \
--header "X-Auth-Key: $CLOUDFLARE_API_KEY" \
```

:::note

Ending slashes included to facilitate copy and paste. Do not include the last slash if this is the last line of the cURL command.
Ending slashes included to facilitate copy and paste. Do not include the last slash if this is the last line of the cURL command.
:::

If using API Token (the preferred authentication method), include the following arguments in the cURL command to add the required HTTP header to the request:

```txt
--header "Authorization: Bearer <API_TOKEN>" \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
```

### Request without body content (`GET`, `DELETE`)
Expand All @@ -66,20 +66,20 @@ For `GET` requests, do not include the `--request GET` command-line argument, si

```txt
curl {full_url_with_placeholders} \
--header "Authorization: Bearer <API_TOKEN>"
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
```

```bash title="Example"
curl https://api.cloudflare.com/client/v4/zones/{zone_id}/firewall/rules \
--header "Authorization: Bearer <API_TOKEN>"
curl https://api.cloudflare.com/client/v4/zones/$ZONE_ID/firewall/rules \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
```

#### `DELETE` request template

```txt
curl --request DELETE \
{full_url_with_placeholders} \
--header "Authorization: Bearer <API_TOKEN>"
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
```

Requests without a body do not need syntax highlight, but we use `bash` syntax highlighting to highlight the several delimited strings.
Expand All @@ -96,16 +96,16 @@ For `POST` requests with a body, do not include the `--request POST` command-lin

```txt
curl {full_url_with_placeholders} \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '({|[)
(...JSON content, pretty printed, using 2-space indents...)
(}|])'
```

```bash title="Example"
curl https://api.cloudflare.com/client/v4/zones/{zone_id}/firewall/rules \
--header "Authorization: Bearer <API_TOKEN>" \
curl https://api.cloudflare.com/client/v4/zones/$ZONE_ID/firewall/rules \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '[
{
Expand All @@ -123,7 +123,7 @@ curl https://api.cloudflare.com/client/v4/zones/{zone_id}/firewall/rules \
```txt
curl --request (PUT/PATCH) \
{full_url_with_placeholders} \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '({|[)
(...JSON content, pretty printed, using 2-space indents...)
Expand All @@ -141,8 +141,8 @@ The recommended way of escaping a single quote inside the body is the following
Which means "close string, add escaped single quote, begin string again".

```bash title="Example"
curl https://api.cloudflare.com/api/v4/zones/{zone_id}/page_shield/policies \
--header "Authorization: Bearer <API_TOKEN>" \
curl https://api.cloudflare.com/api/v4/zones/$ZONE_ID/page_shield/policies \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"value": "script-src myapp.example.com cdnjs.cloudflare.com https://www.google-analytics.com/analytics.js '\''self'\''"
Expand All @@ -156,7 +156,7 @@ If you have a `POST` request without a body, you must add the `--request POST` a
```txt
curl --request POST \
{full_url_with_placeholders} \
--header "Authorization: Bearer <API_TOKEN>"
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
```

### Additional information
Expand All @@ -166,8 +166,8 @@ Code blocks with example requests that include a JSON body should use `bash` syn
### Full request example

```bash
curl https://api.cloudflare.com/api/v4/zones/{zone_id}/page_shield/policies \
--header "Authorization: Bearer <API_TOKEN>" \
curl https://api.cloudflare.com/api/v4/zones/$ZONE_ID/page_shield/policies \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"description": "My first policy in log mode",
Expand Down
Loading