Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced stdin processing #194

Closed
Valodim opened this issue Jan 16, 2014 · 9 comments
Closed

Advanced stdin processing #194

Valodim opened this issue Jan 16, 2014 · 9 comments
Labels
enhancement New feature or enhancement

Comments

@Valodim
Copy link

Valodim commented Jan 16, 2014

Hey there,

I am missing a feature to pass a file as a post field from stdin. My particular use case is this from curl:
command | curl -F 'sprunge=<-' http://sprunge.us
which I noticed is not possible with httpie.

If it's not too much trouble, I would kindly like to request this feature.

@jkbrzt
Copy link
Member

jkbrzt commented Jan 16, 2014

Interesting. Current master allows you to specify file contents as values for fields (via field=@/file/path). And it can in fact be used to take data from STDIN as well:

$ http --version
0.8.0-dev
$ http -v httpbin.org/post stdin_data=@/dev/stdin
Hello World
^D
POST /post HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate, compress
Content-Length: 31
Content-Type: application/json; charset=utf-8
Host: httpbin.org
User-Agent: HTTPie/0.8.0-dev

{
    "stdin_data": "Hello World\n"
}

It currently has the limitation that HTTPie doesn't allow you to specify both request data items on the CLI and pass content via STDIN at the same time though, i.e. this won't work:

$ echo 'Hello World' | http httpbin.org/post stdin_data=@/dev/stdin
http: error: Request body (from stdin or a file) and request data (key=value) cannot be mixed.

STDIN handling is something I'm planning on taking a look at because the current implementation is not ideal, so the limitation might be fixed in the near future.

@jkbrzt
Copy link
Member

jkbrzt commented Jan 16, 2014

Just wondering: when do you actually use this feature?

@Valodim
Copy link
Author

Valodim commented Jan 16, 2014

I didn't think of /dev/stdin for an @ file value. Nice idea.

My use case is, as said above, http://sprunge.us. To be more specific, I wanted to paste a couple of lines from vim, which I normally do like this:

:w !curl -F 'sprunge=<-' http://sprunge.us

@jkbrzt
Copy link
Member

jkbrzt commented Jan 16, 2014

Oh, that's interesting. It seems to work pretty well:

:! http -f sprunge.us sprunge=@/dev/stdin
<paste>
^D

Or, send the content of the current file:

:! http -f sprunge.us sprunge=@%

@Valodim
Copy link
Author

Valodim commented Jan 16, 2014

Great!

The /dev/stdin trick is kind of a stretch though. Some kind of shorthand like curl has would be nice. field=@- or something like that.

Thanks for the quick reply, I'll be waiting for a 0.8.0 release, then :)

@jkbrzt jkbrzt closed this as completed Jan 16, 2014
@saintdev
Copy link

Hi, I came across this because I was also attempting to use the sprunge.us service with httpie, but not from within vim. Could this be reopened? Passing data via a pipe still doesn't work.

$ http --version
0.8.0

$ dmesg | http -f sprunge.us sprunge=@/dev/stdin
usage: http [--json] [--form] [--pretty {all,colors,format,none}]
            [--style STYLE] [--print WHAT] [--verbose] [--headers] [--body]
            [--stream] [--output FILE] [--download] [--continue]
            [--session SESSION_NAME_OR_PATH | --session-read-only SESSION_NAME_OR_PATH]
            [--auth USER[:PASS]] [--auth-type {basic,digest}]
            [--proxy PROTOCOL:PROXY_URL] [--follow] [--verify VERIFY]
            [--timeout SECONDS] [--check-status] [--ignore-stdin] [--help]
            [--version] [--traceback] [--debug]
            [METHOD] URL [REQUEST_ITEM [REQUEST_ITEM ...]]
http: error: Request body (from stdin or a file) and request data (key=value) cannot be mixed.

@jkbrzt jkbrzt reopened this Jan 24, 2015
@jkbrzt jkbrzt changed the title pass a file from stdin Advanced stdin processing Jan 24, 2015
@jkbrzt
Copy link
Member

jkbrzt commented Sep 1, 2015

This is now being worked on here: #370

@jkbrzt jkbrzt closed this as completed Sep 1, 2015
@jaraco
Copy link

jaraco commented Nov 30, 2018

I also would like this feature. I'm grabbing a CSV, posting it to a service, altering the CSV using csvkit, and then want to post the altered version to a service again:

http -f POST http://ourservice/ action=decode file@identifiers.csv | csvcut -c DECODED | http -f POST http://ourcsvservice/ action=encode file@/dev/stdin --ignore-stdin

It would be nice to have been able to use file@- and not have to supply --ignore-stdin.

@cognivore
Copy link

Agreed, @jaraco

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or enhancement
Projects
None yet
Development

No branches or pull requests

5 participants