Curl Command
A request as a runnable curl command, shell-quoted and with secrets masked. This output gets pasted into tickets, and an Authorization header pasted into a ticket is a leaked credential.
src/components/ui/curl-command.tsxAbout
From the component's own source, where it was written.
A request rendered as a runnable curl command.
Every value is shell-quoted with single quotes and an escape for embedded ones. A JSON body pasted straight into a command line is the classic way to produce a command that looks right and silently truncates at the first apostrophe in someone's surname.
Headers matching redact are masked. The whole point of this component is that the output gets pasted into a terminal, a ticket, or a chat — and an Authorization header pasted into a ticket is a leaked credential.
Long commands are broken across lines with a trailing backslash, which is what makes the difference between something a reader can check and a 400-character single line.
Install
npx astralyx-ui add curl-command
Usage
import { CurlCommand } from '@/components/ui/curl-command'
<CurlCommand method="POST" url={url} headers={headers} body={body} />Composer
Change the props and the source below follows.
curl -X POST \
'https://api.example.com/v1/users?limit=25' \
-H 'Content-Type: application/json' \
-H 'Authorization: ••••••••' \
-H 'X-Request-Id: req_8812' \
--data '{
"name": "O'\''Brien",
"role": "admin"
}'<CurlCommand
method="POST"
url={url}
headers={headers}
body={body}
/>Examples
A POST with headers and a body
<CurlCommand method="POST" url="https://api.example.com/v1/refunds" headers={headers} body={body} />A bare GET
<CurlCommand url="https://api.example.com/v1/customers/cus_8812" />
API
Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.
CurlCommand
Extends Omit<ComponentProps<'div'>, 'title'>.
| Prop | Type | Default | Description |
|---|---|---|---|
| method | string | 'GET' | — |
| url | string | required | — |
| headers | CurlHeader[] | [] | — |
| body | string | object | — | An object is JSON-encoded before quoting. |
| redact | RegExp[] | [/^authorization$/i, /^cookie$/i, /api[-_]?key/i, /^x-.*-token$/i] | Header names whose values are masked. Defaults cover Authorization, Cookie, api-key and x-*-token. |
| mask | string | '••••••••' | — |
| insecure | boolean | false | Adds -k. Worth showing when it is genuinely in play. |
| title | string | 'curl' | — |
Functions
| Function | Signature | Description |
|---|---|---|
| shellQuote | (value: string) => string | POSIX single-quoting: end the quote, escape the quote, reopen. |
Types
CurlHeader
A request rendered as a runnable curl command.
| Field | Type | Description |
|---|---|---|
| name | string | — |
| value | string | — |
Behaviour
| Topic | Detail | Description |
|---|---|---|
| quoting | POSIX | Single-quoted with '\'' for embedded quotes. A JSON body pasted raw truncates at the first apostrophe in someone's surname. |
| line breaks | automatic | Backslash continuations — a 400-character single line cannot be reviewed. |