Skip to content

Commit

Permalink
use better known headers in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 9, 2015
1 parent 6c62018 commit ff5cba2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

6.02 2015-03-08
6.02 2015-03-09
- Improved portability of Morbo.

6.01 2015-03-03
Expand Down
12 changes: 6 additions & 6 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -361,11 +361,11 @@ Mojo::UserAgent - Non-blocking I/O HTTP and WebSocket user agent
use Mojo::UserAgent;
# Say hello to the Unicode snowman with "Do Not Track" header
# Say hello to the Unicode snowman with Accept header
my $ua = Mojo::UserAgent->new;
say $ua->get('www.☃.net?hello=there' => {DNT => 1})->res->body;
say $ua->get('www.☃.net?hello=there' => {Accept => '*/*'})->res->body;
# Form POST with exception handling
# Form POST (application/x-www-form-urlencoded) with exception handling
my $tx = $ua->post('https://metacpan.org/search' => form => {q => 'mojo'});
if (my $res = $tx->success) { say $res->body }
else {
Expand All @@ -378,10 +378,10 @@ Mojo::UserAgent - Non-blocking I/O HTTP and WebSocket user agent
say $ua->get('https://sri:s3cret@example.com/search.json?q=perl')
->res->json('/results/0/title');
# Extract data from HTML and XML resources
# Extract data from HTML and XML resources with CSS selectors
say $ua->get('www.perl.org')->res->dom->at('title')->text;
# Scrape the latest headlines from a news site with CSS selectors
# Scrape the latest headlines from a news site
say $ua->get('blogs.perl.org')
->res->dom->find('h2 > a')->map('text')->join("\n");
Expand All @@ -390,7 +390,7 @@ Mojo::UserAgent - Non-blocking I/O HTTP and WebSocket user agent
say $ua->get('api.3g2upl4pq6kufc4m.onion/?q=mojolicious&format=json')
->res->json('/Abstract');
# IPv6 PUT request with content
# IPv6 PUT request with Content-Type header and content
my $tx
= $ua->put('[::1]:3000' => {'Content-Type' => 'text/plain'} => 'Hello!');
Expand Down
11 changes: 4 additions & 7 deletions lib/Mojo/UserAgent/Transactor.pm
Expand Up @@ -265,12 +265,9 @@ Mojo::UserAgent::Transactor - User agent transactor
use Mojo::UserAgent::Transactor;
# Simple GET request
# GET request with Accept header
my $t = Mojo::UserAgent::Transactor->new;
say $t->tx(GET => 'http://example.com')->req->to_string;
# PATCH request with "Do Not Track" header and content
say $t->tx(PATCH => 'example.com' => {DNT => 1} => 'Hi!')->req->to_string;
say $t->tx(GET => 'http://example.com' => {Accept => '*/*'})->req->to_string;
# POST request with form-data
say $t->tx(POST => 'example.com' => form => {a => 'b'})->req->to_string;
Expand Down Expand Up @@ -367,9 +364,9 @@ C<307> or C<308> redirect response if possible.
my $tx = $t->tx(PUT => 'http://example.com' => json => {a => 'b'});
my $tx = $t->tx(POST => 'http://example.com' => {Accept => '*/*'} => 'Hi!');
my $tx = $t->tx(
PUT => 'http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
PUT => 'http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
my $tx = $t->tx(
PUT => 'http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
PUT => 'http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
Versatile general purpose L<Mojo::Transaction::HTTP> transaction builder for
requests, with support for L</"GENERATORS">.
Expand Down

0 comments on commit ff5cba2

Please sign in to comment.