However, the below code perfectly work for me outside Mojolicious App.
use Modern::Perl; use Mojo::Base -strict, -signatures; use Mojo::UserAgent; use Mojo::Promise; use Mojo::IOLoop; use Mojo::Util 'trim'; use Mojo::AsyncAwait; use LWP::UserAgent; use JSON; my $ua = Mojo::UserAgent->new; my $result = $ua->post('http://localhost:8000/api/token/' => json => { username => 'username', password => 'mypassword' }) ->result ->json; my $access_token = $result->{access}; my $refresh_token = $result->{refresh}; print "Access Token: " . $result->{access}, "\n"; print "Refresh Token: " . $result->{refresh}, "\n\n"; $ua = Mojo::UserAgent->new; $result = $ua->post('http://' . 'localhost:8000' . '/api/token/refresh/' => json => { refresh => $refresh_token }) ->result ->json; my $agent = Mojo::UserAgent->new; async post_user_p => sub ($url) { say "\n\n", $url; my $tx = await $agent->post_p( $url, { Authorization => 'Bearer ' . $result->{access}, }, form => {"username" => "username"}, ); return trim from_json($tx->result->body)->{first_name}; }; async main => sub (@urls) { my @promises = map { post_user_p($_) } @urls; my @names = await Mojo::Promise->all(@promises); say for map { $_->[0] } @names; }; my @urls = (qw( http://localhost:8000/api-converge/auth/user/ )); main(@urls)->wait; On Wednesday, 27 May 2020 23:41:27 UTC+5:30, Jeyaraj Durairaj wrote: > > I tried generating an example app and copied pasted the code segment you > posted here and then tried. > > "Action not found!" error is shown. > > Should I reinstall Perl again and then try? > Will it work under morbo or works only on Hypnotoad? > I am using Windows for my development, wherein morbo is the only server I > can test. > Or can I test it on daemon mode and try> > Please suggest as to how I should diagnose it. > I would need this Async/await to be working in my system. > I have tried without Async, all other functionalities rock both in > development and production (hypnotoad). Mojo::UserAgent is amazing to fetch > API call data from Django server (running under Apache). > > I am completely counting on Mojolicious as my primary framework for my new > projects. Please help. > > > Regards/Jeyaraj > > On Wednesday, 27 May 2020 17:46:49 UTC+5:30, Sebastian Riedel wrote: >> >> I'll assume it was you who asked the same question on IRC earlier. Had >> you been sticking around for a bit longer you would have seen my >> instructions for getting a working application that i tested locally. >> >> 14:08 <kraih> to be sure i did a "mojo generate app" and then >> replaced the controller with http://paste.scsys.co.uk/589044 >> >> That's the important part, if that doesn't work your Perl or some module >> you installed is broken. >> >> -- >> sebastian >> > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/mojolicious/126ed3a6-bb0a-4a8c-8d6d-12e27701f187%40googlegroups.com.