I'm trying to pass the cat
output to curl:
$ cat file | curl --data '{"title":"mytitle","input":"-"}' http://api
But input
is literally a -
.
I'm trying to pass the cat
output to curl:
$ cat file | curl --data '{"title":"mytitle","input":"-"}' http://api
But input
is literally a -
.
You can use the magical stdin file
/dev/stdin
I spent a while trying to figure this out and got it working with the following:
Curl documentation for
-d
optionDepending of your HTTP endpoint, server configuration, you should be good by using this format:
curl -d @data.json http://api
Sounds like you want to wrap the content of
input
in a JSON body, and then have that sent over with a POST request. I think that the simplest way to do that is to manipulate stdin first and then push that over to curl using-d @-
. One way could look like this:I'm using
<(echo)
to usecat
to merge strings and files, but there is almost certainly a better way.Keep in mind that this does not escape the contents of
file
and that you may run into issues because of that.Try