Skip to content

carapace-sh/carapace-bin / skills/httpie

Use when working with HTTPie (http/https CLI) — the command-line HTTP client for the API era. Covers request items syntax (headers, params, data fields, file uploads), authentication (basic, digest, bearer, plugins), session management, output formatting and printing, SSL/TLS configuration, download mode, configuration files, environment variables, plugin system, exit codes, scripting, and URL syntax. Triggers on: "httpie", "http command", "https command", "http --json", "http --form", "http --download", "http --session", "http --auth", "http --auth-type", "http --print", "http --verbose", "http --follow", "http --offline", "http --check-status", "http --proxy", "http --ssl", "http --cert", "http --verify", "http --format-options", "http --pretty", "http --style", "http --stream", "http --boundary", "http --multipart", "http --raw", "httpie config", "HTTPIE_CONFIG_DIR", "httpie cli plugins", "request items", "data fields", "URL parameters", "HTTP headers", "raw JSON fields", "file upload fields", "named session", "anonymous session", "read-only session", "Content-Disposition", "httpie-unixsocket", "httpie plugins", "AuthPlugin", "TransportPlugin", "ConverterPlugin", "FormatterPlugin".

FileKindSize
SKILL.mdskill md8.2 KB
references/auth.mdmarkdown3.3 KB
references/cli.mdmarkdown6.6 KB
references/config.mdmarkdown4.0 KB
references/downloads.mdmarkdown3.7 KB
references/output.mdmarkdown6.1 KB
references/plugins.mdmarkdown5.6 KB
references/request-items.mdmarkdown4.9 KB
references/scripting.mdmarkdown3.7 KB
references/sessions.mdmarkdown5.0 KB
references/ssl.mdmarkdown2.8 KB
references/url-syntax.mdmarkdown3.5 KB

references/scripting.md

View on GitHub
# Scripting and Exit Codes

Using HTTPie in shell scripts, automation, and pipelines — exit codes, `--check-status`, stdin handling, and best practices.

## Exit Codes

Without `--check-status`, HTTPie exits with `0` unless a network or fatal error occurs. With `--check-status`, HTTP status codes map to exit codes:

| Exit Code | Meaning |
|-----------|---------|
| `0` | Success (no errors, no bad status codes) |
| `1` | General error (e.g., download body not fully downloaded) |
| `2` | Request timed out |
| `3` | HTTP 3xx Redirection (when `--follow` is not set) |
| `4` | HTTP 4xx Client Error |
| `5` | HTTP 5xx Server Error |
| `6` | Exceeded `--max-redirects=N` redirects |

## Shell Script Example

```bash
#!/bin/bash

if http --check-status --ignore-stdin --timeout=2.5 HEAD pie.dev/get &> /dev/null; then
    echo 'OK!'
else
    case $? in
        2) echo 'Request timed out!' ;;
        3) echo 'Unexpected HTTP 3xx Redirection!' ;;
        4) echo 'HTTP 4xx Client Error!' ;;
        5) echo 'HTTP 5xx Server Error!' ;;
        6) echo 'Exceeded --max-redirects=<n> redirects!' ;;
        *) echo 'Other Error!' ;;
    esac
fi
```

## Best Practices for Automation

### Use `--ignore-stdin`

In non-interactive contexts (cron jobs, scripts), stdin is not connected to a terminal. HTTPie assumes piped input contains a request body and will **hang** waiting for data. Always use `--ignore-stdin` in scripts, unless you are intentionally piping data:

```bash
# Correct — prevents hanging
$ http --ignore-stdin pie.dev/get

# Correct — piping data intentionally
$ echo '{"name": "John"}' | http pie.dev/post
```

### Use `--timeout`

Prevent unresponsive scripts by setting a connection timeout:

```bash
$ http --timeout=2.5 pie.dev/get
```

### Recommended Flags for Scripts

```bash
http --check-status --ignore-stdin --timeout=<seconds> <METHOD> <URL>
```

### Suppress All Output

Use `-qq` (quiet twice) with `--check-status` for completely silent operation:

```bash
$ http -qq --check-status pie.dev/post enjoy='the silence'
```

## Piping Data Into HTTPie

### From a File

```bash
$ http PUT pie.dev/put X-API-Token:123 < files/data.json
```

### From Another Command

```bash
$ grep '401 Unauthorized' /var/log/httpd/error_log | http POST pie.dev/post
```

### Bash Here String

```bash
$ http pie.dev/post <<<'{"name": "John"}'
```

### Chaining HTTP Requests

```bash
$ http GET https://api.github.com/repos/httpie/cli | http POST pie.dev/post
```

### Interactive Paste

```bash
$ cat | http POST pie.dev/post
<paste data>
^D
```

Data from stdin **cannot** be combined with data fields specified on the command line.

## `--raw` Flag

Pass raw request data without processing:

```bash
$ http --raw='{"name": "John"}' pie.dev/post
```

## Redirected Output Defaults

When output is piped or redirected, HTTPie changes defaults for convenience:

| Aspect | Terminal | Redirected |
|--------|----------|-----------|
| Formatting | Enabled (`--pretty=all`) | Disabled (`--pretty=none`) |
| Colors | Enabled | Disabled |
| Default content | Headers + body | Body only |
| Binary data | Suppressed | Not suppressed |

Override with `--pretty`:

```bash
$ http --pretty=all pie.dev/get | less -R
```

## Download Mode and Exit Codes

`--download` implies `--check-status` and `--follow`. If the body is not fully downloaded, HTTPie exits with code `1`. See [downloads.md](downloads.md).

## References

- Source of truth: <https://httpie.io/docs/cli/scripting>
- Carapace completer: `completers/common/http_completer/cmd/root.go`

## Related Skills

- [cli.md](cli.md) — full flag reference
- [downloads.md](downloads.md) — download mode and `--check-status`
- [output.md](output.md) — redirected output behavior
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 322kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 322kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 322kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 322kUpdated Claude CodeCodexVerifiedInstall