Skip to content

--stdin support — read YAML request from stdin #157

@xaaha

Description

@xaaha

Summary

Allow hulak to read a YAML request definition from stdin instead of requiring a file on disk.

Problem

Today, every request requires a .hk.yaml file. For one-off requests or automation, this means creating a temp file, running hulak, then cleaning up:

cat > /tmp/req.hk.yaml << 'EOF'
method: POST
url: https://api.example.com/users
body:
  raw: '{"name": "John"}'
EOF
hulak -fp /tmp/req.hk.yaml
rm /tmp/req.hk.yaml

Proposed behavior

# Pipe YAML directly
echo 'method: GET
url: https://httpbin.org/get' | hulak --stdin

# Heredoc for multi-line
hulak --stdin << 'EOF'
method: POST
url: https://api.example.com/users
headers:
  Content-Type: application/json
body:
  raw: '{"name": "John"}'
EOF

# Combine with --quiet for full automation
cat request.yaml | hulak --stdin --quiet | jq '.response.body'

When --stdin is set:

  • Read YAML from stdin instead of a file
  • Parse it through the same yamlparser pipeline as file-based requests
  • -env flag still works for template variable resolution
  • No _response.json file is saved (no source file to derive the name from), response goes to stdout only

Implementation notes

  • The YAML parsing path already exists in pkg/yamlparser/ — this just needs a new input source
  • Detect stdin via os.Stdin stat or the --stdin flag
  • Template actions like {{.token}} should still resolve from env files
  • Actions like {{getValueOf ...}} and {{getFile ...}} should still work (they reference the filesystem, not the input source)

Parent

Part of #154 — v0.3 ergonomics

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestepic: ergonomicsIssues that belong to the authoring and discovery ergonomics epic

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions