question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request to add `-d, --data` option for raw body like curl

See original GitHub issue

The request is simple, just to add an option to pass raw data like curl does:

http :/api/user -d 'MyRawData...'

I know that in mostly cases if you are sending JSON or form data, it can be achieved with the “request items”, like:

http :/api/hey say=Hello to=me …

And it will converted to the proper format depending of the content type, that is awesome! And if you have something that is not a JSON or form data to send, you can do something like:

echo 'MyRawData...' | http :/api/hey

But this is impractical, the main idea of HTTPie is cURL-like tool for humans , and this case is far of that principle, in fact, curl is more practical than HTTPie for the previous example. Adding more than one command and pipe them with ugly characters like | < just because a simple option is missing doesn’t sound human-friendly.

What’s wrong with add the -d option to http?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:16
  • Comments:22 (8 by maintainers)

github_iconTop GitHub Comments

16reactions
qoomoncommented, Jan 25, 2018

you can just do http POST example.org <<< "foo bar" or http POST example.org < file.name

7reactions
jakubroztocilcommented, Oct 31, 2016

What’s wrong with add the -d option to http?

There’d be nothing particularly wrong with that. I just find piping cleaner and strongly prefer when there is only one way of doing the same thing. Piping exists for this very purpose (i.e. to pass data to programs), and It’s easy to understand, universal, and unambiguous. Every decent CLI tool supports piping (with the notable exception of curl) so you only need to learn the concept once.

Compare:

httpie

A universal method for passing request data is through redirected stdin (standard input). Such data is buffered and then with no further processing used as the request body.

curl

-d, --data <data>
              (HTTP)  Sends  the  specified data in a POST request to the HTTP server, in the same way that a browser
              does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass
              the  data  to  the  server  using  the  content-type application/x-www-form-urlencoded.  Compare to -F,
              --form.

              -d, --data is the same as --data-ascii. --data-raw is almost the same  but  does  not  have  a  special
              interpretation of the @ character. To post data purely binary, you should instead use the --data-binary
              option.  To URL-encode the value of a form field you may use --data-urlencode.

              If any of these options is used more than once on the same command line, the data pieces specified will
              be merged together with a separating &-symbol. Thus, using '-d name=daniel -d skill=lousy' would gener-
              ate a post chunk that looks like 'name=daniel&skill=lousy'.

              If you start the data with the letter @, the rest should be a file name to read the data from, or -  if
              you  want  curl  to read the data from stdin. Multiple files can also be specified. Posting data from a
              file named 'foobar' would thus be done with --data @foobar. When --data is told to  read  from  a  file
              like  that,  carriage  returns  and newlines will be stripped out. If you don't want the @ character to
              have a special interpretation use --data-raw instead.
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to post raw body data with curl? - Stack Overflow
curl's --data will by default send Content-Type: application/x-www-form-urlencoded in the request header. However, when using Postman's raw ...
Read more >
How do I post request body with Curl? - ReqBin
To send binary data in the body of a POST message with Curl, use the --data-binary command-line option.
Read more >
How To Post Raw Body Data With Curl? - ADocLib
The request is simple just to add an option to pass raw data like curl does: http :/api/user d 'MyRawData.' I know that...
Read more >
Request data via --raw - HTTPie 3.2.1 (latest) docs
In a situation when piping data via stdin is not convenient (for example, when generating API docs examples), you can specify the raw...
Read more >
curl.1 the man page
If you want a progress meter for HTTP POST or PUT requests, you need to redirect the ... Like -d, --data the default...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found