fetch automatically formats and syntax-highlights response bodies based on content type.
Control response body formatting:
| Value | Description |
|---|---|
auto |
Format when stdout is a terminal (default) |
on |
Always format output |
off |
Never format output |
fetch --format off example.com/api # Raw output
fetch --format on example.com/api # Force formattingControl syntax highlighting:
| Value | Description |
|---|---|
auto |
Color when stdout is a terminal (default) |
on |
Always use colors |
off |
Never use colors |
fetch --color off example.com/api # No colors
fetch --color on example.com/api | less -R # Colors piped to lessContent-Types: application/json, */*+json, */*-json
Features:
- Pretty-printing with proper indentation
- Syntax highlighting for keys, strings, numbers, booleans, null
fetch example.com/api/usersOutput:
{
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"active": true
}Content-Types: application/xml, text/xml, */*+xml
Features:
- Proper indentation
- Color-coded elements, attributes, and content
fetch example.com/api/data.xmlOutput:
<?xml version="1.0" encoding="UTF-8"?>
<users>
<user id="1">
<name>John Doe</name>
<email>john@example.com</email>
</user>
</users>Content-Types: application/yaml, application/x-yaml, text/yaml, text/x-yaml, */*+yaml
Features:
- Syntax highlighting for keys, string values, comments, anchors/aliases, tags, and document markers
- Original formatting preserved exactly
fetch example.com/config.yamlOutput:
server:
host: localhost
port: 8080
features:
- auth
- loggingContent-Type: text/html
Features:
- Proper indentation of nested elements
- Syntax highlighting
- Embedded CSS handling
fetch example.comUse --article to extract the main readable content from an HTML response and
convert it to Markdown with Legible:
fetch --article example.com/post
fetch --article --format off example.com/post > post.md
fetch --article -o post.md example.com/postThe converted HTML document starts with YAML frontmatter containing
available article metadata such as title, byline, site_name,
published_time, lang, dir, length, and excerpt. It also includes
url, set to the final response URL after redirects. Relative links are
resolved against that URL.
If the response is already text/markdown or text/x-markdown, its Markdown
fetch uses the body directly and adds only url as frontmatter.
Article extraction is a body transformation rather than terminal presentation:
--format, --color, and --pager only control how the resulting Markdown is
displayed. Output files receive raw, uncolored Markdown. Extraction requires
buffering the decoded HTML and therefore has a 16 MiB response limit.
Content-Type: text/css
Features:
- Selector highlighting
- Property and value coloring
- Proper indentation
fetch example.com/styles.cssContent-Types: text/markdown, text/x-markdown
Features:
- Syntax highlighting for headings, bold, italic, code spans, links, images
- Fenced code block delegation to JSON, YAML, XML, HTML, CSS formatters
- Blockquote and list marker highlighting
fetch example.com/README.mdContent-Types: text/csv, application/csv
Features:
- Column alignment for readability
- Vertical "record view" for data that does not fit the terminal width
fetch example.com/data.csvStandard output (fits terminal):
name email age
John Doe john@example.com 30
Jane Smith jane@example.com 25
Vertical mode (wide data):
--- Record 1 ---
name: John Doe
email: john@example.com
age: 30
--- Record 2 ---
name: Jane Smith
email: jane@example.com
age: 25
Content-Types: application/msgpack, application/x-msgpack, application/vnd.msgpack
Features:
- Automatic conversion to JSON format
- Same formatting as JSON responses
fetch example.com/api/data.msgpackContent-Types: application/protobuf, application/x-protobuf, application/x-google-protobuf, application/vnd.google.protobuf, */*+proto
Features:
- Wire format parsing (without schema)
- Field number display
- With gRPC schema: field names and proper types
Without schema (generic parsing):
1: "John Doe"
2: 30
3: "john@example.com"
With a schema (with --proto-file or --proto-desc):
{
"name": "John Doe",
"age": 30,
"email": "john@example.com"
}See gRPC documentation for schema-aware formatting.
Content-Type: text/event-stream
Features:
- Streaming output as events arrive
- SSE-shaped
event:anddata:output fetchformats and highlights JSONdata:payloads- Request timeouts still apply to long-running event streams
fetch example.com/eventsOutput:
event: message
data: { "text": "Hello!", "user": "john" }
event: message
data: { "text": "Hi there!", "user": "jane" }
When color is enabled, fetch highlights event and data labels. It applies
the JSON theme to JSON values inside data:. In automatic compression mode,
fetch retries compressed SSE responses to GET and HEAD requests without
Accept-Encoding. For other methods, it keeps the compressed response and gives
a warning. For immediate SSE streaming with another method, use
--compress off.
Content-Types: application/x-ndjson, application/ndjson, application/x-jsonl, application/jsonl, application/x-jsonlines
Features:
- Streaming output line by line
- Each line formatted as JSON
fetch example.com/stream.ndjsonOutput:
{"id": 1, "event": "start"}
{"id": 2, "event": "data", "value": 42}
{"id": 3, "event": "end"}Content-Type: image/*
fetch renders images directly in the terminal. See Image
Rendering for details.
Write response body to a file:
fetch -o response.json example.com/api/dataWhen writing to a file, fetch disables formatting. By default, it continues to
decode compression. If the response uses Content-Encoding for a .gz, .br,
or .zst asset, use --compress off for a byte-for-byte download.
Force output to stdout, bypassing binary detection:
fetch -o - example.com/file.bin > output.binSave to current directory using filename from URL:
fetch -O example.com/files/document.pdf
# Creates ./document.pdfUse filename from Content-Disposition header. If no usable header filename is
available, fetch warns and falls back to the URL filename:
fetch -O -J example.com/download
# Uses server-provided filenameOverwrite existing files:
fetch -o output.json --clobber example.com/dataBy default, fetch sends response bodies to a pager when stdout is a terminal.
Image responses bypass the pager. As a result, the terminal can interpret its native
image protocols.
Use --pager auto to page terminal stdout, --pager on to force the pager, or --pager off to disable it.
fetch --pager off example.com/large-responseWhen paging is enabled, fetch uses $PAGER if it is set. Set NO_PAGER to
disable the default auto pager. If $PAGER is unset, fetch falls back to
less -FIRX. When $LESS is set, fetch runs less without adding its default
flags so your LESS options apply. $PAGER is split with POSIX shell-style
quoting, but fetch launches the pager directly and does not interpret shell
operators such as pipes or redirects.
The fallback less -FIRX flags are:
-F- Quit if output fits on screen-I- Case-insensitive search-R- Handle ANSI colors-X- Do not clear the screen on exit
When stdout is a terminal, fetch checks if the response appears to be binary data. If so, it displays a warning instead of corrupting your terminal:
warning: the response body appears to be binary (content type: application/octet-stream)
To force output:
fetch -o file.dat example.com/binary.dat
fetch -o - example.com/binary.datSet defaults in your configuration file:
# Always format output
format = on
# Disable colors
color = off
# Disable pager
pager = offfetch --format off example.com/api | jq '.users[0]'fetch --format on example.com/api | tee response.jsonfetch --format on --color on example.com/api | less -Rfetch --compress off -o archive.tar.gz example.com/archive.tar.gz- CLI Reference - All formatting options
- Image Rendering - Terminal image display
- Configuration - Default settings