みんな大好きパイプ処理。
小分けに作成できて、僕は好きです。
さて、今回はそんなパイプ芸をCurlでも使う方法をば。
標準入出力は"-"で表現される事が多いですが、このCurlでもそんなノリ"@-"で使えます。
実際のところで
echoで出力したJSONをCurlのデータペイロードで使うには、以下のように”@-”で。
$ echo '{"data":{"A":100, "B":200}' | curl -X POST -H "Content-Type: application/json;charset=UTF-8" --data @- YOURDIST.PAGE
"@"より後にファイル名をつければ、ローカルファイルになります。
$ curl -X POST -H "Content-Type: application/json;charset=UTF-8" --data @YOURFILE YOURDIST.PAGE
これらは、manでは以下のように説明されています。
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.
参考もと
- man curl