Intro to API Development with Mojolicous Matt Monsen.

Post on 16-Dec-2015

218 views 0 download

Tags:

Transcript of Intro to API Development with Mojolicous Matt Monsen.

Intro to API Development with MojolicousMatt 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

use Mojolicious::Lite;

get '/' => { text => ’I <3 Perl!’ };

app->start;

These three lines are a whole web application

Getting Started

$ morbo perl.pl Server available at http://127.0.0.1:3000.

$ curl http://127.0.0.1:3000/ I <3 Perl!

To run this example with the built-in development web server

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

Routing – Controller – Action

Rendering

Rendering

Deployment

CGIPSGI

Daemon

Deployment

Daemon

MorboDevelopment Server

HypnotoadHot-code reloading production server

Deployment

Run Development Mode$ morbo script/helloServer available at http://127.0.0.1:3000

Morbo

Deployment

Run & Reload$ hypnotoad script/hello

Stop$ hypnotoad –s script/hello

Hypnotoad

Testing

Testing

$ perl script/hello testRunning tests from '/home/matt/hello/t’.script/../t/basic.t .. okAll tests successful.Files=1, Tests=3, 1 wallclock secs ( 0.03 usr 0.01 sys + 0.32 cusr 0.04 csys = 0.40 CPU)Result: PASS

Mojocasts.com