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.tsx

About

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
bash
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"
}'
Props
tsx
<CurlCommand
  method="POST"
  url={url}
  headers={headers}
  body={body}
/>

Examples

A POST with headers and a body

A bare GET

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'>.

PropTypeDefaultDescription
methodstring'GET'—
urlstringrequired—
headersCurlHeader[][]—
bodystring | object—An object is JSON-encoded before quoting.
redactRegExp[][/^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.
maskstring'••••••••'—
insecurebooleanfalseAdds -k. Worth showing when it is genuinely in play.
titlestring'curl'—

Functions

FunctionSignatureDescription
shellQuote(value: string) => stringPOSIX single-quoting: end the quote, escape the quote, reopen.

Types

CurlHeader

A request rendered as a runnable curl command.

FieldTypeDescription
namestring—
valuestring—

Behaviour

TopicDetailDescription
quotingPOSIXSingle-quoted with '\'' for embedded quotes. A JSON body pasted raw truncates at the first apostrophe in someone's surname.
line breaksautomaticBackslash continuations — a 400-character single line cannot be reviewed.