IruP has asked for the wisdom of the Perl Monks concerning the following question:

2017-10-07 Note added by Athanasius: This node was copied from StackOverflow. See also Re: Extract specify values in file log using perl.


The Mojolicious has two methods to access POST body: body_params and json

What is the benefit of them?

UPD I think, it will be more handy if body_params returns hash if body is recognized by some parser and body_type will return the name of this parser. Thus if it were POST from form body_type will return application/x-www-form-urlencoded

  • Comment on Why Mojolicious has two methods to access POST body?

Replies are listed 'Best First'.
Re: Why Mojolicious has two methods to access POST body?
by Corion (Patriarch) on Sep 07, 2017 at 10:47 UTC

    I think whatever method you use is dictated by the protocol that you specified between your client application and the server application.

    If you specify that the POST body is a JSON document, then you should the ->json method in your server.

    If you specify that the POST body is application/x-www-form-urlencoded (because you don't have a Javascript-driven fancy web frontent but something that can fall back to plain HTML), then you should use the ->body_params method.

    Mixing the two or adding magic recognition will only bite you later when you discover that you have a badly specified protocol for your applications.