Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
better examples for using STDIN/STDOUT with the get command
  • Loading branch information
kraih committed May 28, 2017
1 parent 93f9c3d commit 2d371c3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,7 +1,8 @@

7.32 2017-05-28
- Added -f option to get command.
- Improved get command with support for piping data to STDIN.
- Improved get command with support for passing request data by redirecting
STDIN.
- Fixed memory leak in Mojo::IOLoop::Client that sometimes prevented the
connect timeout from working correctly for TLS handshakes.

Expand Down
6 changes: 3 additions & 3 deletions lib/Mojolicious/Command/get.pm
Expand Up @@ -142,10 +142,10 @@ Mojolicious::Command::get - Get command
mojo get mojolicious.org
mojo get -v -r -o 25 -i 50 google.com
mojo get -v -H 'Host: mojolicious.org' -H 'Accept: */*' mojolicious.org
mojo get -M POST -H 'Content-Type: text/trololo' -c 'trololo' perl.org
mojo get mojolicious.org > example.html
mojo get -M PUT mojolicious.org < example.html
mojo get -f 'q=Mojolicious' -f 'size=5' https://metacpan.org/search
mojo get -M POST -f 'upload=@some_file.txt' mojolicious.org
mojo get -M PUT mojolicious.org < some_file.txt
mojo get -M POST -f 'upload=@example.html' mojolicious.org
mojo get mojolicious.org 'head > title' text
mojo get mojolicious.org .footer all
mojo get mojolicious.org a attr href
Expand Down
17 changes: 12 additions & 5 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -1447,20 +1447,27 @@ You can also extract all text from nested child elements.

The request can be customized as well.

$ mojo get -M POST -c 'Hello!' http://mojolicious.org
$ mojo get -H 'X-Bender: Bite my shiny metal ass!' http://google.com
$ mojo get -M POST -H 'X-Bender: Bite my shiny metal ass!' http://google.com

Pipe data to be sent with the request to C<STDIN>.
Store response data by redirecting C<STDOUT>.

$ mojo get mojolicious.org > example.html

Pass request data by redirecting C<STDIN>.

$ mojo get -M PUT mojolicious.org < example.html

Or use the output of another program.

$ echo 'Hello World' | mojo get -M PUT http://mojolicious.org

Submit forms as C<application/x-www-form-urlencoded> content.

$ mojo get -M POST -f 'q=Mojo' -f 'size=5' https://metacpan.org/search

Or upload files as C<multipart/form-data> content.
And upload files as C<multipart/form-data> content.

$ mojo get -M POST -f 'upload=@some_file.txt' mojolicious.org
$ mojo get -M POST -f 'upload=@example.html' mojolicious.org

You can follow redirects and view the headers for all messages.

Expand Down

0 comments on commit 2d371c3

Please sign in to comment.