Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Mojolicious to serve more openAPIs

by Anonymous Monk
on Feb 08, 2019 at 09:47 UTC ( #1229605=perlquestion: print w/replies, xml ) Need Help??

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

I want to set up a webserver that provides two or more APIs.

The APIs would be described according to OpenAPI 3.0 specification (

I understand that Mojolicious would allow to add routes and input/output validation starting from the JSON API specification.

The webserver is running Apache and hosts various virtualhosts.

I wonder if this is compatible with Mojolicious and I'd like to have some suggestion on how to implement the architecture so to provide the two APIs (that are completely unrelated) as:

Also, is Mojolicious the best choice? I only have experience with CGI and Apache Web Server.

Thank you

Replies are listed 'Best First'.
Re: Mojolicious to serve more openAPIs
by Anonymous Monk on Feb 08, 2019 at 16:44 UTC
    I have modified existing Apache virtual servers so that they listen to port 8080 instead of 80.

    Then I have installed NGINX to receive connections to port 80 and defined one server block for each Apache virtual server with proxy_pass set to the correponding Apache virtual server.

    This allows me to use all the existing CGI applications.

    I have then created a server block for the new with proxy_pass set to localhost:3000:

    server { listen 80; listen [::]:80; server_name; location / { proxy_pass http://localhost:3000; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #try_files $uri $uri/ =404; } }
    Then I have created two Mojolicious apps, to be mounted via Toadfarm:

    #!/usr/bin/perl use Toadfarm -init; mount "/path/to/" => { "X-Request-Base" => "" }; mount "/path/to/" => { "X-Request-Base" => "" }; start ["http://*:3000"], workers => 8;
    And I've created the files /path/to/

    use Mojolicious::Lite; get '/' => {text => 'Hello! api01 here'}; app->start;
    and /path/to/

    use Mojolicious::Lite; get '/' => {text => 'Hello! api02 here'}; app->start;
    I can then start the script:

    $ ./ start [2019-02-08 17:17:49.47784] [63828] [info] Mounting api01 with conditi +ons [2019-02-08 17:17:49.48110] [63828] [info] Mounting api02 with conditi +ons * Starting the process api_start_pl ...done. (already running with pid=63819)
    But from browser and give me a "Raptor not found Mojolicios message".

    Any suggestion? Thanks.

    2019-02-10 Athanasius changed <pre> to <code> tags

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1229605]
Approved by dorko
Front-paged by haukex
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2019-10-19 02:15 GMT
Find Nodes?
    Voting Booth?