Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Feature request: Allow redirected output along with terminal output in the same invocation #136

Open
peritus opened this Issue · 1 comment

2 participants

@peritus

Thanks for httpie!

I'd really like to be able to have httpie output colorized, pretty-printed, with-headers to the terminal while saving the uncolorized, raw body without headers to a file.

I wrote a very simple shell script (paraphrasing below) to consume my rest API, and i'd like to print the interaction to terminal while also processing this programatically.

BASE_URL="http://localhost:8080"

while [ true ]; do

    # do something with the last response
    # here without having to GET it again

    read -p "> " ACTION
    if [[ "$ACTION" == /* ]]; then
        LINK=$BASE_URL$ACTION
        http --print=Hhb GET $LINK
    elif [[ "$ACTION" == \{* ]]; then
        http --print=Hhb $LINK --body|\
        underscore extend "$ACTION"|\
        http --print=Hhbb PUT $LINK
    fi
done

Normally I'd use tee but that strips the pretty. If I force the pretty, I'd have to remove it for programatic consumption as well as remove the headers, so solving this in httpie sounds like a reasonably good idea.

Perhaps this is possible right now, but I didn't find the correct order of arguments after thoroughly investigating. Or my shell-fu is too weak — in both cases please forgive and enlighten me.

@jakubroztocil

@peritus, have a look at the new --download option. It doesn't do exactly what you're asking for, but it allows you to redirect the body and still see colorised response headers in the terminal (and you get a progress bar as a bonus).

The tee-like output might be added to HTTPie at a later stage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.