220 likes | 293 Views
Intro to API Development with Mojolicous. Matt Monsen. Features. An amazing real-time web framework. Very clean, portable and Object Oriented pure-Perl API. Full stack HTTP and WebSocket client/server implementation. Built-in non-blocking I/O web server.
E N D
Intro to API Development with Mojolicous Matt Monsen
Features • An amazing real-time web framework. • Very clean, portable and Object Oriented pure-Perl API. • Full stack HTTP and WebSocket client/server implementation. • Built-in non-blocking I/O web server. • Automatic CGI and PSGI detection. • JSON and HTML/XML parser with CSS selector support.
Installation $ curl get.mojolicio.us| sh
Getting Started These three lines are a whole web application useMojolicious::Lite; get'/' => {text=> ’I <3 Perl!’ }; app->start;
Getting Started To run this example with the built-in development web server $ morboperl.pl Server available at http://127.0.0.1:3000. $ curl http://127.0.0.1:3000/ I <3 Perl!
Getting Started To run this example with the built-in development web server
$ mojo generate app Hello [mkdir] /home/matt/hello/script [write] /home/matt/hello/script/hello [chmod] hello/script/hello 744 [mkdir] /home/matt/hello/lib [write] /home/matt/hello/lib/Hello.pm [mkdir] /home/matt/hello/lib/Hello [write] /home/matt/hello/lib/Hello/Example.pm [mkdir] /home/matt/hello/t [write] /home/matt/hello/t/basic.t [mkdir] /home/matt/hello/log [mkdir] /home/matt/hello/public [write] /home/matt/hello/public/index.html [mkdir] /home/matt/hello/templates/layouts [write] /home/matt/hello/templates/layouts/default.html.ep [mkdir] /home/matt/hello/templates/example [write] /home/matt/hello/templates/example/welcome.html.ep
$ mojo generate app Hello [mkdir] /home/matt/hello/script [write] /home/matt/hello/script/hello [chmod] hello/script/hello 744 [mkdir] /home/matt/hello/lib [write] /home/matt/hello/lib/Hello.pm [mkdir] /home/matt/hello/lib/Hello [write] /home/matt/hello/lib/Hello/Example.pm [mkdir] /home/matt/hello/t [write] /home/matt/hello/t/basic.t [mkdir] /home/matt/hello/log [mkdir] /home/matt/hello/public [write] /home/matt/hello/public/index.html [mkdir] /home/matt/hello/templates/layouts [write] /home/matt/hello/templates/layouts/default.html.ep [mkdir] /home/matt/hello/templates/example [write] /home/matt/hello/templates/example/welcome.html.ep
Deployment CGI PSGI Daemon
Deployment Daemon Morbo Development Server Hypnotoad Hot-code reloading production server
Deployment Morbo Run Development Mode $ morbo script/hello Server available at http://127.0.0.1:3000
Deployment Hypnotoad Run & Reload $ hypnotoad script/hello Stop $ hypnotoad –s script/hello
Testing $ perlscript/hello test Running tests from '/home/matt/hello/t’. script/../t/basic.t .. ok All tests successful. Files=1, Tests=3, 1 wallclocksecs ( 0.03 usr 0.01 sys + 0.32 cusr 0.04 csys = 0.40 CPU) Result: PASS