I don't know what your authentication scheme is for the 3rd party, but the process ought to be pretty simple using Mojolicious:

use Mojolicious::Lite; # Hit PerlMonks. If a node ID is supplied, fetch it. get '/*resource' => { resource => '' } => sub { my $self = shift; my $uri = "http://www.perlmonks.org/"; my $resource = $self->stash('resource'); $uri .= length $resource ? "?node_id=$resource" : ''; $self->ua->get( $uri => sub { my ($ua, $tx) = @_; $self->render( text => $tx->res->dom->html ); }); }; app->start;

Fire it up: ./myapp.pl daemon. Then hit http://localhost:3000. You'll get the Monastery Gates. Now try http://localhost:3000/992634, and you'll fetch this node.

This basic example doesn't exercise any care in processing the resource request. That's up to you. And if you need to modify some aspect of the incoming request, the level of difficulty depends on what needs altering. A simple change to the restful request is easy, though. And of course you're not limited to listening on port 3000, but you can read about that in the docs.

In case you blinked and missed it, this starts up a daemon that listens on a port for http requests. When a request comes in as a 'get', it adds a new domain to the URL, but passes through the resource params to that URL. Then the built-in user agent fetches that resource, and the renderer renders it back to the client as HTML.

I'd encourage you to watch the mojocast that discusses using the user-agent. It demonstrates using SSL, constructing transations, and a lot more. And for help in dealing with placeholders in your routes, this mojocast.


Dave


In reply to Re: Proxying web API requests by davido
in thread Proxying web API requests by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.