Async/await in Mojolicious Full App

220 views
Skip to first unread message

Jeyaraj Durairaj

unread,
May 26, 2020, 2:06:50 PM5/26/20
to Mojolicious
Hi,

I am working in one of the leading Healthcare company and am making an internal Business Intelligence application using Mojolicious with data support from Django API.

Even though I could have made the entire application in Django itself, because I love perl and Mojolicious, I would like to get this done in Mojolicious and want my application to go live and serve top leaders.

While I am able to get what I want, I am struggling to fulfill the need of writing Async action in Mojolicious::Controller class.
I have hosted my application in Ubuntu machine and running in Hypnotoad with help of 'Carton'.


[2020-05-26 23:18:18.85262] [-16240] [error] syntax error at C:/.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 39, near "async on_user_login_p"
Can't redeclare "my" in "my" at C:/.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 44, near "my"
syntax error at C:/.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 58, near "}"
Can't redeclare "my" in "my" at C:/.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 62, near "my"
syntax error at C:/.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 75, near "}"
syntax error at C:/.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 86, near "}"
Compilation failed in require at (eval 659) line 1.


==========================CODES=================================
package ConvergeAtCommex::Controller::Sessions;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::Base -async_await;
use Mojo::UserAgent;
use Mojo::Promise;

# This action will render a template
async on_user_login_p => sub {
    my $self = shift;
    
    # Authenticate by sending the request parameters directly
    if ($self->authenticate($self->param('username'), $self->param('password'))) {
        my $access_token = $self->access_token($self->session('refresh_token'));
        my $user = await $self->user_data_p($access_token);
        return $self->render(text => 'Unauthenticated Access', status => 403) unless ($user->{is_staff});
        return $self->render(text => 'You are not an active User', status => 403) unless ($user->{is_active});
        $self->set_authorization($user);
        $self->flash(message_type => 'success');
        $self->flash(message => 'Congratulations ' . $self->session('full_name') . '!');
        $self->redirect_to('bi-home');
    } else {
        $self->flash(message_type => 'danger');
        $self->flash(message => 'Wrong SSOID/Password!');
        return $self->redirect_to('login', status => 403);
        #return $self->render(text => 'wrong ssoid/password', status => 403);
    }
};

async sub user_data_p () {
    my ($c, $access_token) = @_;
    my $ua = Mojo::UserAgent->new;
    my $tx = await $ua->post_p(
        'http://' . $c->config->{API_IP} . '/api-converge/auth/user/',
        {
            Authorization => 'Bearer ' . $access_token,
        },
        form => {username => $c->session('username')}, 

    );
    if ($tx->is_success) {
        return from_json($tx->result->body);
    }
    $c->render(text => 'User Data can not be obtained', status => 500);
}


Vincent Tondellier

unread,
May 26, 2020, 2:11:23 PM5/26/20
to mojol...@googlegroups.com, Jeyaraj Durairaj
On Tuesday 26 May 2020 11:06:50 Jeyaraj Durairaj wrote :
> use Mojo::Base 'Mojolicious::Controller';
> use Mojo::Base -async_await;

Try instead:

use Mojo::Base 'Mojolicious::Controller', -async_await;

Dan Book

unread,
May 26, 2020, 2:12:47 PM5/26/20
to mojol...@googlegroups.com
On Tue, May 26, 2020 at 2:06 PM Jeyaraj Durairaj <jeyaraj....@gmail.com> wrote:
async on_user_login_p => sub {

async sub user_data_p () {

These two declarations are not quite right in different ways. The first one is giving you a syntax error because it isn't any supported syntax. Just do "async sub foo {"

-Dan 

Jeyaraj Durairaj

unread,
May 26, 2020, 2:29:09 PM5/26/20
to Mojolicious
Hi,

I corrected it.

But, I am still getting the syntax error and the following log.


use Mojo::Base 'Mojolicious::Controller', -async_await, -signatures;


# This action will render a template
async sub on_user_login_p ($self) {
    $self->render_later;
    
    # Authenticate by sending the request parameters directly
    if ($self->authenticate($self->param('username'), $self->param('password'))) {
        my $access_token = $self->access_token($self->session('refresh_token'));
        my $user = await $self->user_data_p($access_token);
        return $self->render(text => 'Unauthenticated Access', status => 403) unless ($user->{is_staff});
        return $self->render(text => 'You are not an active User', status => 403) unless ($user->{is_active});
        $self->set_authorization($user);
        $self->flash(message_type => 'success');
        $self->flash(message => 'Congratulations ' . $self->session('full_name') . '!');
        $self->redirect_to('bi-home');
    } else {
        $self->flash(message_type => 'danger');
        $self->flash(message => 'Wrong SSOID/Password!');
        return $self->redirect_to('login', status => 403);
        #return $self->render(text => 'wrong ssoid/password', status => 403);
    }
}

async sub user_data_p ($c, $access_token) {
    my $ua = Mojo::UserAgent->new;
    my $tx = await $ua->post_p(
        'http://' . $c->config->{API_IP} . '/api-converge/auth/user/',
        {
            Authorization => 'Bearer ' . $access_token,
        },
        form => {username => $c->session('username')}, 

    );
    if ($tx->is_success) {
        return from_json($tx->result->body);
    }
    $c->render(text => 'User Data can not be obtained', status => 500);
}



[2020-05-26 23:53:56.00449] [-15696] [debug] GET "/" (e7a8d2e9)
[2020-05-26 23:53:56.01464] [-15696] [error] syntax error at C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 38, near "async sub on_user_login_p ($self) "
Global symbol "$self" requires explicit package name (did you forget to declare "my $self"?) at C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 39.
Global symbol "$self" requires explicit package name (did you forget to declare "my $self"?) at C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 42.
Global symbol "$self" requires explicit package name (did you forget to declare "my $self"?) at C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 42.
Global symbol "$self" requires explicit package name (did you forget to declare "my $self"?) at C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 42.
Global symbol "$self" requires explicit package name (did you forget to declare "my $self"?) at C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 43.
Global symbol "$self" requires explicit package name (did you forget to declare "my $self"?) at C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 43.
Global symbol "$self" requires explicit package name (did you forget to declare "my $self"?) at C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 44.
Global symbol "$self" requires explicit package name (did you forget to declare "my $self"?) at C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 45.
Global symbol "$self" requires explicit package name (did you forget to declare "my $self"?) at C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 46.
Global symbol "$self" requires explicit package name (did you forget to declare "my $self"?) at C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 47.
Global symbol "$self" requires explicit package name (did you forget to declare "my $self"?) at C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 48.
Global symbol "$self" requires explicit package name (did you forget to declare "my $self"?) at C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 49.
Global symbol "$self" requires explicit package name (did you forget to declare "my $self"?) at C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 49.
Global symbol "$self" requires explicit package name (did you forget to declare "my $self"?) at C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 50.
Global symbol "$self" requires explicit package name (did you forget to declare "my $self"?) at C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 52.
Global symbol "$self" requires explicit package name (did you forget to declare "my $self"?) at C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 53.
Global symbol "$self" requires explicit package name (did you forget to declare "my $self"?) at C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 54.
syntax error at C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm line 57, near "}"
C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm has too many errors.
Compilation failed in require at (eval 659) line 1.

[2020-05-26 23:53:56.01609] [-15696] [debug] Template "exception.development.html.ep" not found
[2020-05-26 23:53:56.01711] [-15696] [debug] Template "exception.html.ep" not found
[2020-05-26 23:53:56.01927] [-15696] [debug] Rendering template "mojo/debug.html.ep"
[2020-05-26 23:53:56.08608] [-15696] [debug] 500 Internal Server Error (0.081533s, 12.265/s)
[2020-05-26 23:53:57.75761] [-15696] [debug] GET "/" (a91d3077)
[2020-05-26 23:53:57.75823] [-15696] [debug] Routing to controller "ConvergeAtCommex::Controller::Sessions" and action "is_authenticated"
[2020-05-26 23:53:57.75904] [-15696] [debug] 302 Found (0.001412s, 708.215/s)
[2020-05-26 23:53:57.76139] [-15696] [debug] Routing to controller "ConvergeAtCommex::Controller::BusinessIntelligence" and action "index"
[2020-05-26 23:53:57.76250] [-15696] [debug] Rendering template "business_intelligence/index.html.ep"
[2020-05-26 23:53:57.77103] [-15696] [debug] Rendering template "business_intelligence/_unapproved.html.ep"
[2020-05-26 23:53:57.77651] [-15696] [debug] Rendering template "business_intelligence/_test.html.ep"
[2020-05-26 23:53:57.78271] [-15696] [debug] Rendering template "layouts/_country_footer.html.ep"
[2020-05-26 23:53:57.78699] [-15696] [debug] Rendering template "layouts/default.html.ep"
[2020-05-26 23:53:57.79491] [-15696] [debug] Rendering template "layouts/_mojo_default.html.ep"
[2020-05-26 23:53:57.80086] [-15696] [debug] Rendering template "layouts/_shim.html.ep"
[2020-05-26 23:53:57.80362] [-15696] [debug] Rendering template "layouts/_site_header.html.ep"
[2020-05-26 23:53:57.80667] [-15696] [debug] Rendering template "layouts/_right_navigation.html.ep"
[2020-05-26 23:53:57.81295] [-15696] [debug] Rendering template "layouts/_site_footer.html.ep"
[2020-05-26 23:53:57.83392] [-15696] [debug] GET "/login" (96b58437)
[2020-05-26 23:53:57.83532] [-15696] [debug] Routing to controller "ConvergeAtCommex::Controller::Sessions" and action "login"
[2020-05-26 23:53:57.83608] [-15696] [debug] Rendering template "sessions/login.html.ep"
[2020-05-26 23:53:57.84332] [-15696] [debug] Rendering cached template "layouts/default.html.ep"
[2020-05-26 23:53:57.84381] [-15696] [debug] Rendering cached template "layouts/_mojo_default.html.ep"
[2020-05-26 23:53:57.84428] [-15696] [debug] Rendering cached template "layouts/_shim.html.ep"
[2020-05-26 23:53:57.84484] [-15696] [debug] Rendering cached template "layouts/_site_header.html.ep"
[2020-05-26 23:53:57.84502] [-15696] [debug] Rendering cached template "layouts/_right_navigation.html.ep"
[2020-05-26 23:53:57.84611] [-15696] [debug] Rendering cached template "layouts/_site_footer.html.ep"
[2020-05-26 23:53:57.84689] [-15696] [debug] 200 OK (0.012977s, 77.059/s)
[2020-05-26 23:54:00.80700] [-15696] [debug] GET "/login" (f5c021e3)
[2020-05-26 23:54:00.80737] [-15696] [debug] Routing to controller "ConvergeAtCommex::Controller::Sessions" and action "login"
[2020-05-26 23:54:00.80758] [-15696] [debug] Rendering cached template "sessions/login.html.ep"
[2020-05-26 23:54:00.81043] [-15696] [debug] Rendering cached template "layouts/default.html.ep"
[2020-05-26 23:54:00.81101] [-15696] [debug] Rendering cached template "layouts/_mojo_default.html.ep"
[2020-05-26 23:54:00.81149] [-15696] [debug] Rendering cached template "layouts/_shim.html.ep"
[2020-05-26 23:54:00.81253] [-15696] [debug] Rendering cached template "layouts/_site_header.html.ep"
[2020-05-26 23:54:00.81346] [-15696] [debug] Rendering cached template "layouts/_right_navigation.html.ep"
[2020-05-26 23:54:00.81655] [-15696] [debug] Rendering cached template "layouts/_site_footer.html.ep"
[2020-05-26 23:54:00.81950] [-15696] [debug] 200 OK (0.012424s, 80.489/s)
[2020-05-26 23:54:23.71050] [-15696] [debug] POST "/login" (05c91967)
[2020-05-26 23:54:23.71154] [-15696] [debug] Routing to controller "ConvergeAtCommex::Controller::Sessions" and action "on_user_login_p"
[2020-05-26 23:54:23.71169] [-15696] [debug] Action not found in controller
[2020-05-26 23:54:23.71255] [-15696] [debug] Template "sessions/on_user_login_p.html.ep" not found
[2020-05-26 23:54:23.71347] [-15696] [debug] Template "not_found.development.html.ep" not found
[2020-05-26 23:54:23.71433] [-15696] [debug] Template "not_found.html.ep" not found
[2020-05-26 23:54:23.71480] [-15696] [debug] Rendering cached template "mojo/debug.html.ep"
[2020-05-26 23:54:23.73582] [-15696] [debug] 404 Not Found (0.025269s, 39.574/s)




On Tuesday, 26 May 2020 23:42:47 UTC+5:30, Dan Book wrote:

Jeyaraj Durairaj

unread,
May 26, 2020, 2:30:00 PM5/26/20
to Mojolicious
I tried. getting the same error.

Sebastian Riedel

unread,
May 27, 2020, 8:16:49 AM5/27/20
to Mojolicious
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

Jeyaraj Durairaj

unread,
May 27, 2020, 12:09:08 PM5/27/20
to Mojolicious
Oops! my bad. Apologies! I should have stayed. But, I had to get into a skype call.

I will follow your advise and redo all and confirm sir.

Sebastian Riedel

unread,
May 27, 2020, 1:32:36 PM5/27/20
to Mojolicious
Oops! my bad. Apologies! I should have stayed. But, I had to get into a skype call.

IRC is rarely synchronous, if you can't wait a few hours for an answer just stick to the mailing-list and
forget IRC. The friendly folks in #mojo will answer almost any question, but you might have to wait
24 hours for the right person to be online. We are distributed all around the world after all.

--
sebastian 

Jeyaraj Durairaj

unread,
May 27, 2020, 1:49:55 PM5/27/20
to Mojolicious
Sure sir, I will stick to it.

Jeyaraj Durairaj

unread,
May 27, 2020, 2:11:27 PM5/27/20
to Mojolicious
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

Jeyaraj Durairaj

unread,
May 27, 2020, 2:36:04 PM5/27/20
to Mojolicious
I have uninstalled and reinstalled perl.
I am getting the same error.

Jeyaraj Durairaj

unread,
May 27, 2020, 2:40:48 PM5/27/20
to Mojolicious
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(
));

main(@urls)->wait;




On Wednesday, 27 May 2020 23:41:27 UTC+5:30, Jeyaraj Durairaj wrote:

Jeyaraj Durairaj

unread,
May 28, 2020, 4:45:04 AM5/28/20
to Mojolicious
any luck on the solutions?

-- Jeyaraj

Jeyaraj Durairaj

unread,
Jun 4, 2020, 2:36:01 AM6/4/20
to Mojolicious
Hi,

Eureka! Eureka! It works!.

The solution I found (because of my error) is that I uninstalled Mojo::AsyncAwait and installed Future::AsyncAwait.
It just works!

By June end, my business intelligence application will be live to serve 100+ users with insights and analytics.

(To apply icing on the cake, I have plugged in Moose also in to model layer for my application)

As Glen Hinkle said, it is really really a fun to work in Mojolicious. I love Hypnotoad.

BTW, I am doing a private project as well to help a home designer to launch a web site for their small firm. Guess! what framework I am gonna use.. Mojolicious.

Thanks to Mojo group and special thanks to SRI as well.

-- Jeyaraj

Jeyaraj Durairaj

unread,
Jun 4, 2020, 3:31:42 AM6/4/20
to Mojolicious
Hi,

It works for helpers as well with the following declaration.

    $app->helper(summary_data => async sub ($c, $access_token) {
        my $ua = Mojo::UserAgent->new;

        my $tx = await $ua->post_p(
            'http://' . $c->config->{API_IP} . '/api-app/analytics/summary/',
            { Authorization => 'Bearer ' . $access_token },
            form => { periods => encode_json([ $c->session('cx_current_quarter') ]) }, 
        );
        if ($tx->result->is_success) {
            return from_json($tx->result->body);
        }
        $c->flash(message_type => 'warning');
        $c->flash(message => 'Could not get summary data');
        return $c->redirect_to('cx-summary', status => 403);
    });




-- Jeyaraj

Stefan Adams

unread,
Jun 5, 2020, 5:25:04 PM6/5/20
to mojolicious
Great job pushing your application forward with Async/Await!  Looking at your snippet, here's one small change you can probably make using the json() method from Mojo::Message:

    $app->helper(summary_data => async sub ($c, $access_token) {
        my $ua = Mojo::UserAgent->new;

        my $tx = await $ua->post_p(
            'http://' . $c->config->{API_IP} . '/api-app/analytics/summary/',
            { Authorization => 'Bearer ' . $access_token },
            json => { periods => $c->session('cx_current_quarter') }, 
        );
        if ($tx->result->is_success) {
            return $tx->result->json;
        }
        $c->flash(message_type => 'warning');
        $c->flash(message => 'Could not get summary data');
        return $c->redirect_to('cx-summary', status => 403);
    });


--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mojolicious/debdea2d-2f67-4feb-814d-9d936d1b6732%40googlegroups.com.

Jeyaraj Durairaj

unread,
Jun 6, 2020, 6:50:00 AM6/6/20
to Mojolicious
Hi Stefan,

Thanks for the appreciation and the ideas.

I will surely do the following change in my code.

changing to return $tx->result->json; from  return from_json($tx->result->body); 

However, following change has been tricky to me.

changing to  json => { periods => $c->session('cx_current_quarter') },  from  form => { periods => encode_json([ $c->session('cx_current_quarter') ]) },

 I, per se, tried json => { periods => $c->session('cx_current_quarter') } at the outset. It did not work.

The reason I found is the following:

"json =>" works for the API call without "Authorization Header"
my $tx = await $ua->post_p('http://' . $c->config->{API_IP} . '/api/token/refresh/' => json => { refresh => $refresh_token });

only "form =>" works for the API call with Authorization Header" 
$tx = await $ua->post_p(
            'http://' . $c->config->{API_IP} . '/api-app/analytics/summary/',
            { Authorization => 'Bearer ' . $access_token },
            form => { periods => $c->session('cx_current_quarter') }, 
        );

The difference between json and form in this context was intentional or accidental. More comments on this will be appreciated!

Thanks.
-- Jeyaraj
To unsubscribe from this group and stop receiving emails from it, send an email to mojol...@googlegroups.com.

Stefan Adams

unread,
Jun 6, 2020, 9:41:47 AM6/6/20
to mojolicious
form and json are examples of "content generators".  You can think of them as request macros.  form, for example, "generates query string, application/x-www-form-urlencoded or multipart/form-data content" while json, for example, "generates application/json content with Mojo::JSON."

So, true, changing the content generator as I recommended changes how the request is sent to the server.  But you can also create your own custom generators if you need to, such as an application/x-www-form-urlencoded content expecting a JSON value for a form parameter as yours seems to expect.

Indeed, without knowing anything about your API, I recommended a change for how you send your request, completely blindly and contrary to what the API endpoint may be expecting.  I assumed the API endpoint would handle a JSON request, but instead it seems to want a JSON string as the value to the periods parameter of the form.

To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mojolicious/ae2e9c20-e50a-4b67-a7a2-b103d7d8b728o%40googlegroups.com.

Jeyaraj Durairaj

unread,
Jun 6, 2020, 9:47:05 AM6/6/20
to Mojolicious
Honored to receive answers and responses from experts in the first place.
Your tips and ideas are indeed essential to me.

Happy to be in Mojolicious discussions and sharing ideas!

-- Jeyaraj


On Saturday, 6 June 2020 19:11:47 UTC+5:30, Stefan Adams wrote:
form and json are examples of "content generators".  You can think of them as request macros.  form, for example, "generates query string, application/x-www-form-urlencoded or multipart/form-data content" while json, for example, "generates application/json content with Mojo::JSON."

So, true, changing the content generator as I recommended changes how the request is sent to the server.  But you can also create your own custom generators if you need to, such as an application/x-www-form-urlencoded content expecting a JSON value for a form parameter as yours seems to expect.

Indeed, without knowing anything about your API, I recommended a change for how you send your request, completely blindly and contrary to what the API endpoint may be expecting.  I assumed the API endpoint would handle a JSON request, but instead it seems to want a JSON string as the value to the periods parameter of the form.

Jeyaraj Durairaj

unread,
Jun 18, 2020, 7:43:38 AM6/18/20
to Mojolicious
Hi,

Just to share that I have successfully deployed Mojolicious (Full App) based BI application in production with Hynotoad along with Async/Await feature, DBIx:Class model layer, Mojo::Pg Model layer, API calls with Mojo::UserAgent (with Async/Await).

Mojo::Test feature is also amazing.


Special thanks to Luc Didry
for the following link which has helped me in deployment.



-- Jeyaraj
Reply all
Reply to author
Forward
0 new messages