mason how to call outside WEB API

396 views Asked by At

I am using mason to call an API(web based, I can use GET to call it) so that a json file can be returned.

I know m->comp() can be used inside. But what function can be used externally?

1

There are 1 answers

0
fhuntern On

Sounds like you want to make an http request to an external url. Since you're just embedding perl in html you could just have a perl block that uses HTTP::Request and LWP::UserAgent to make that request. Something like this:

my $ua = LWP::UserAgent->new;
my $response = $ua->request( HTTP::Request->new( "GET", "http://https://api.twitter.com/1/users/show.json?screen_name=aplusk" ) );
my $data = $response->content();

Then have HTML::Mason do whatever you want it to do with the json $data