Catalyst-Plugin-ResponseFrom

 view release on metacpan or  search on metacpan

README.mkdn  view on Meta::CPAN

# NAME

Catalyst::Plugin::ResponseFrom - Use the response of a public endpoint.

# SYNOPSIS

    package MyApp;
    use Catalyst 'ResponseFrom';

    MyApp->setup;

    package MyApp::Controller::Example;

    use Moose;
    use MooseX::MethodAttributes;
    use HTTP::Request::Common;

    extends 'Catalyst::Controller';

    sub as_http_request :Local {
      my ($self, $c) = @_;
      $c->redispatch_to(GET $c->uri_for($self->action_for('target')));
    }

    sub as_spec :Local {
      my ($self, $c) = @_;
      $c->redispatch_to('GET' => $c->uri_for($self->action_for('target')));
    }

    sub collect_response :Local {
      my ($self, $c) = @_;
      my $http_response = $c->http_response_from(GET => $c->uri_for($self->action_for('target')));
    }

    sub target :Local {
      my ($self, $c) = @_;
      $c->response->content_type('text/plain');
      $c->response->body("This is the target action");
    }

# DESCRIPTION

[Catalyst](https://metacpan.org/pod/Catalyst) allows you to forward to a private named actions, but there is no
built in method to 'forward' to a public URL.  You might want to do this rather
than (for example) issue a redirect.

Additionally there is no 'subrequest' like feature (and [Catalyst::Plugin::Subrequest](https://metacpan.org/pod/Catalyst::Plugin::Subrequest)
uses internal hacks to function).  There maye be cases, such as in testing, where
it would be great to be able to issue a public URL request and collect the response.

This plugin is an attempt to give you these features in a clean manner that does not
rely on internal [Catalyst](https://metacpan.org/pod/Catalyst) details that are subject to change.  However you must be
using a more modern version of [Catalyst](https://metacpan.org/pod/Catalyst) (the current requirement is 5.90060).

# METHODS

This plugin adds the following methods to your [Catalyst](https://metacpan.org/pod/Catalyst) application.  All methods
share the same function signature (this approach and following documentation 'borrowed'
from [Web::Simple](https://metacpan.org/pod/Web::Simple)):

       my $psgi_response = $app->http_response_from(GET => '/' => %headers);
       my $http_response = $app->http_response_from(POST => '/' => %headers_or_form);
       $c->redispatch_to($http_request);



( run in 0.880 second using v1.01-cache-2.11-cpan-39bf76dae61 )