Skip to content

Conversation

@KianNH
Copy link
Member

@KianNH KianNH commented Apr 10, 2025

Summary

Add query prop to APIRequest and CURL

Screenshots (optional)

image

@hyperlint-ai
Copy link
Contributor

hyperlint-ai bot commented Apr 10, 2025

Howdy and thanks for contributing to our repo. The Cloudflare team reviews new, external PRs within two (2) weeks. If it's been two weeks or longer without any movement, please tag the PR Assignees in a comment.

We review internal PRs within 1 week. If it's something urgent or has been sitting without a comment, start a thread in the Developer Docs space internally.


PR Change Summary

Added a query property to the APIRequest and CURL components to allow for URL query parameters.

  • Introduced a query prop in the APIRequest component for URL query parameters.
  • Updated CURL documentation to include examples of using the query prop.
  • Specified the type of the query prop as Record<string, string> in both components.

Modified Files

  • src/content/docs/style-guide/components/api-request.mdx
  • src/content/docs/style-guide/components/curl.mdx

How can I customize these reviews?

Check out the Hyperlint AI Reviewer docs for more information on how to customize the review.

If you just want to ignore it on this PR, you can add the hyperlint-ignore label to the PR. Future changes won't trigger a Hyperlint review.

Note specifically for link checks, we only check the first 30 links in a file and we cache the results for several hours (for instance, if you just added a page, you might experience this). Our recommendation is to add hyperlint-ignore to the PR to ignore the link check for this PR.

@KianNH KianNH force-pushed the kian/PCX-16863 branch 2 times, most recently from 278cc8f to dcf63e0 Compare April 15, 2025 11:01
@pedrosousa
Copy link
Contributor

Nit:
I don't think it will affect any of our cURL/API examples, but I noticed that repeated keys in the query string are not supported by the component (it uses the last value only), while being a valid query string.

Example:

<CURL
  url="https://httpbin.org/anything"
  method="POST"
  json={{
    key: "va'l'ue",
  }}
  query={{
    foo: "bar",
    foo: "baz",
    bar: "baz",
  }}
  code={{
    mark: "value",
  }}
/>

Result:

curl "https://httpbin.org/anything?foo=baz&bar=baz" \
  --request POST \
  --json '{
    "key": "va'\''l'\''ue"
  }'

Expected result:

curl "https://httpbin.org/anything?foo=bar&foo=baz&bar=baz" \
  --request POST \
  --json '{
    "key": "va'\''l'\''ue"
  }'

MDN has a JavaScript example with a repeated key:

const url = new URL("https://example.com?foo=1&bar=2");
const params = new URLSearchParams(url.search);

// Add a second foo parameter.
params.append("foo", 4);
console.log(params.toString()); // Prints 'foo=1&bar=2&foo=4'

@KianNH
Copy link
Member Author

KianNH commented Apr 22, 2025

Nit: I don't think it will affect any of our cURL/API examples, but I noticed that repeated keys in the query string are not supported by the component (it uses the last value only), while being a valid query string.

Example:

<CURL
  url="https://httpbin.org/anything"
  method="POST"
  json={{
    key: "va'l'ue",
  }}
  query={{
    foo: "bar",
    foo: "baz",
    bar: "baz",
  }}
  code={{
    mark: "value",
  }}
/>

Result:

curl "https://httpbin.org/anything?foo=baz&bar=baz" \
  --request POST \
  --json '{
    "key": "va'\''l'\''ue"
  }'

Expected result:

curl "https://httpbin.org/anything?foo=bar&foo=baz&bar=baz" \
  --request POST \
  --json '{
    "key": "va'\''l'\''ue"
  }'

MDN has a JavaScript example with a repeated key:

const url = new URL("https://example.com?foo=1&bar=2");
const params = new URLSearchParams(url.search);

// Add a second foo parameter.
params.append("foo", 4);
console.log(params.toString()); // Prints 'foo=1&bar=2&foo=4'

Added support for this in 52177d9 - something like query: { foo: ["bar", "baz"] } would now result in ?foo=bar&foo=baz.


### `query`

**type:** `Record<string, string>`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KianNH We should probably update the type here, since we now support Array values.

@KianNH KianNH enabled auto-merge (squash) April 22, 2025 18:55
@KianNH KianNH merged commit bc17de3 into production Apr 22, 2025
12 checks passed
@KianNH KianNH deleted the kian/PCX-16863 branch April 22, 2025 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants