++ed by:
FILIN RWSTAUNER FVOX TEMPIRE STEPHEN

112 PAUSE user(s)
140 non-PAUSE user(s).

Sebastian Riedel

NAME

Mojo::UserAgent::Transactor - User agent transactor

SYNOPSIS

  use Mojo::UserAgent::Transactor;

  # Simple GET request
  my $t = Mojo::UserAgent::Transactor->new;
  say $t->tx(GET => 'http://mojolicio.us')->req->to_string;

  # PATCH request with "Do Not Track" header and content
  say $t->tx(PATCH => 'mojolicio.us' => {DNT => 1} => 'Hi!')->req->to_string;

  # POST request with form data
  say $t->tx(POST => 'kraih.com' => form => {a => 'b'})->req->to_string;

  # PUT request with JSON data
  say $t->tx(PUT => 'http://kraih.com' => json => {a => 'b'})->req->to_string;

DESCRIPTION

Mojo::UserAgent::Transactor is the transaction building and manipulation framework used by Mojo::UserAgent.

ATTRIBUTES

Mojo::UserAgent::Transactor implements the following attributes.

generators

  my $generators = $t->generators;
  $t             = $t->generators({foo => sub {...}});

Registered generators.

METHODS

Mojo::UserAgent::Transactor inherits all methods from Mojo::Base and implements the following new ones.

new

  my $t = Mojo::UserAgent::Transactor->new;

Construct a new transactor and register form and json generators.

add_generator

  $t = $t->add_generator(foo => sub {...});

Register a new generator.

endpoint

  my ($proto, $host, $port) = $t->endpoint(Mojo::Transaction::HTTP->new);

Actual endpoint for transaction.

peer

  my ($proto, $host, $port) = $t->peer(Mojo::Transaction::HTTP->new);

Actual peer for transaction.

proxy_connect

  my $tx = $t->proxy_connect(Mojo::Transaction::HTTP->new);

Build Mojo::Transaction::HTTP proxy connect request for transaction if possible.

redirect

  my $tx = $t->redirect(Mojo::Transaction::HTTP->new);

Build Mojo::Transaction::HTTP followup request for 301, 302, 303, 307 or 308 redirect response if possible.

tx

  my $tx = $t->tx(GET  => 'kraih.com');
  my $tx = $t->tx(POST => 'http://kraih.com');
  my $tx = $t->tx(GET  => 'http://kraih.com' => {DNT => 1});
  my $tx = $t->tx(PUT  => 'http://kraih.com' => 'Hi!');
  my $tx = $t->tx(PUT  => 'http://kraih.com' => form => {a => 'b'});
  my $tx = $t->tx(PUT  => 'http://kraih.com' => json => {a => 'b'});
  my $tx = $t->tx(POST => 'http://kraih.com' => {DNT => 1} => 'Hi!');
  my $tx = $t->tx(
    PUT  => 'http://kraih.com' => {DNT => 1} => form => {a => 'b'});
  my $tx = $t->tx(
    PUT  => 'http://kraih.com' => {DNT => 1} => json => {a => 'b'});

Versatile general purpose Mojo::Transaction::HTTP transaction builder for requests, with support for generators.

  # Inspect generated request
  say $t->tx(GET => 'mojolicio.us' => {DNT => 1} => 'Bye!')->req->to_string;

  # Streaming response
  my $tx = $t->tx(GET => 'http://mojolicio.us');
  $tx->res->body(sub { say $_[1] });

  # Custom socket
  my $tx = $t->tx(GET => 'http://mojolicio.us');
  $tx->connection($sock);

  # Use form generator with custom charset
  my $tx = $t->tx(
    PUT => 'http://kraih.com' => form => {a => 'b'} => charset => 'UTF-8');

  # Multiple form values with the same name
  my $tx = $t->tx(PUT => 'http://kraih.com' => form => {a => [qw(b c d)]});

  # Multipart upload streamed from file
  my $tx = $t->tx(
    PUT => 'http://kraih.com' => form => {mytext => {file => '/foo.txt'}});

  # Multipart upload with in-memory content
  my $tx = $t->tx(
    POST => 'http://kraih.com' => form => {mytext => {content => 'lalala'}});

  # Upload multiple files
  my $tx = $t->tx(POST => 'http://kraih.com' =>
    form => {mytext => [{content => 'first'}, {content => 'second'}]});

  # Customized upload with filename and header
  my $tx = $t->tx(POST => 'http://kraih.com' => form => {
    myzip => {
      file     => Mojo::Asset::Memory->new->add_chunk('lalala'),
      filename => 'foo.zip',
      DNT      => 1
    }
  });

While the "multipart/form-data" content type will be automatically used instead of "application/x-www-form-urlencoded" when necessary, you can also enforce it by setting the header manually.

upgrade

  my $tx = $t->upgrade(Mojo::Transaction::HTTP->new);

Build Mojo::Transaction::WebSocket followup transaction for WebSocket handshake if possible.

websocket

  my $tx = $t->websocket('ws://localhost:3000');
  my $tx = $t->websocket('ws://localhost:3000' => {DNT => 1});

Versatile Mojo::Transaction::HTTP transaction builder for WebSocket handshake requests.

SEE ALSO

Mojolicious, Mojolicious::Guides, http://mojolicio.us.