Mojolicious::Lite(3)

๐Ÿ’… Mojolicious::Lite(3) โ€” the micro real-time web framework ๐Ÿฆ‹

okay so bestie, you're reading the Mojolicious::Lite(3) page (User Contributed Perl Documentation, no less ๐Ÿ‘‘) and honestly? it's giving starter-pack energy for building web apps in like... a dozen Perl functions. no cap. ๐ŸŽ€


โœจ NAME โœจ

Mojolicious::Lite โ€” Micro real-time web framework ๐Ÿ’–


โœจ SYNOPSIS โœจ

like, here's the whole vibe in one go:

# Automatically enables "strict", "warnings", "utf8" and Perl 5.16 features
use Mojolicious::Lite -signatures;

# Route with placeholder
get '/:foo' => sub ($c) {
  my $foo = $c->param('foo');
  $c->render(text => "Hello from $foo.");
};

# Start the Mojolicious command system
app->start;

that's it. that's the app. she's tiny. ๐Ÿ”ฅ


โœจ DESCRIPTION โœจ

Mojolicious::Lite is a tiny domain specific language built around Mojolicious, made up of only about a dozen Perl functions. literally a dozen. she's lowkey minimal and highkey iconic ๐Ÿ’…

On Perl 5.20+ you can also use a -signatures flag to enable support for subroutine signatures. slay, modern Perl ๐Ÿซถ

use Mojolicious::Lite -signatures;

get '/:foo' => sub ($c) {
  my $foo = $c->param('foo');
  $c->render(text => "Hello from $foo.");
};

app->start;

See Mojolicious::Guides::Tutorial for more! go read it, i'll wait ๐Ÿ“


๐ŸŒฑ GROWING ๐ŸŒฑ

so Mojolicious::Guides::Growing will give you a detailed introduction to growing a Mojolicious::Lite prototype into a well-structured Mojolicious application โ€” but here we've collected a few snippets that illustrate very well just how similar both of them are. like, siblings energy. same brain, different font. ๐Ÿงš

๐Ÿ›ฃ๏ธ Routes

the functions get, post and friends all have equivalent methods, so nothing gets left behind:

# Mojolicious::Lite
get '/foo' => sub ($c) {
  $c->render(text => 'Hello World!');
};

# Mojolicious
sub startup ($self) {

  my $routes = $self->routes;
  $routes->get('/foo' => sub ($c) {
    $c->render(text => 'Hello World!');
  });
}

๐Ÿ’œ Application

the application object you can access with the function app is the first argument passed to the startup method. main character energy fr:

# Mojolicious::Lite
app->max_request_size(16777216);

# Mojolicious
sub startup ($self) {
  $self->max_request_size(16777216);
}

๐Ÿ”Œ Plugins

instead of the plugin function you just use the method plugin in Mojolicious. same word, different outfit:

# Mojolicious::Lite
plugin 'Config';

# Mojolicious
sub startup ($self) {
  $self->plugin('Config');
}

๐Ÿงธ Helpers

similar to plugins, instead of the helper function you just use the method helper in Mojolicious:

# Mojolicious::Lite
helper two => sub ($c) {
  return 1 + 1;
};

# Mojolicious
sub startup ($self) {
  $self->helper(two => sub ($c) {
    return 1 + 1;
  });
}

๐ŸŒณ Under

instead of sequential function calls, we can use methods to build a tree with nested routes โ€” which, ngl, that much better illustrates how routes work internally. it's giving family tree ๐ŸŒˆ

# Mojolicious::Lite
under '/foo';
get '/bar' => sub ($c) {...};

# Mojolicious
sub startup ($self) {

  my $routes = $self->routes;
  my $foo = $routes->under('/foo');
  $foo->get('/bar' => sub ($c) {...});
}

๐Ÿ’– FUNCTIONS ๐Ÿ’–

Mojolicious::Lite implements the following functions, which are automatically exported. autoloaded besties, you don't even have to ask ๐Ÿ˜Œ

any

my $route = any '/:foo' => sub ($c) {...};
my $route = any '/:foo' => sub ($c) {...} => 'name';
my $route = any '/:foo' => {foo => 'bar'} => sub ($c) {...};
my $route = any '/:foo' => [foo => qr/\w+/] => sub ($c) {...};
my $route = any ['GET', 'POST'] => '/:foo' => sub ($c) {...};
my $route = any ['GET', 'POST'] => '/:foo' => [foo => qr/\w+/] => sub ($c) {...};
my $route = any ['GET', 'POST'] => '/:foo' => (agent => qr/Firefox/) => sub ($c) {...};

generate a route with any in Mojolicious::Routes::Route โ€” matching any of the listed HTTP request methods, or literally all of them, she's flexible like that. see Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information. ๐Ÿ’ซ

app

my $app = app;

returns the Mojolicious::Lite application object, which is a subclass of Mojolicious. your whole app, in one variable ๐ŸŽ€

# Use all the available attributes and methods
app->log->level('error');
app->defaults(foo => 'bar');

del

my $route = del '/:foo' => sub ($c) {...};
my $route = del '/:foo' => sub ($c) {...} => 'name';
my $route = del '/:foo' => {foo => 'bar'} => sub ($c) {...};
my $route = del '/:foo' => [foo => qr/\w+/] => sub ($c) {...};
my $route = del '/:foo' => (agent => qr/Firefox/) => sub ($c) {...};

generate a route with delete in Mojolicious::Routes::Route, matching only DELETE requests. see Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information. ๐Ÿ—‘๏ธ

get

my $route = get '/:foo' => sub ($c) {...};
my $route = get '/:foo' => sub ($c) {...} => 'name';
my $route = get '/:foo' => {foo => 'bar'} => sub ($c) {...};
my $route = get '/:foo' => [foo => qr/\w+/] => sub ($c) {...};
my $route = get '/:foo' => (agent => qr/Firefox/) => sub ($c) {...};

generate a route with get in Mojolicious::Routes::Route, matching only GET requests. see Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information. ๐ŸŒธ

group

group {...};

start a new route group. group chat for routes, honestly ๐Ÿ’ฌ

helper

helper foo => sub ($c, @args) {...};

add a new helper with helper in Mojolicious. ๐Ÿงธ

hook

hook after_dispatch => sub ($c) {...};

share code with hook in Mojolicious. ๐Ÿช

options

my $route = options '/:foo' => sub ($c) {...};
my $route = options '/:foo' => sub ($c) {...} => 'name';
my $route = options '/:foo' => {foo => 'bar'} => sub ($c) {...};
my $route = options '/:foo' => [foo => qr/\w+/] => sub ($c) {...};
my $route = options '/:foo' => (agent => qr/Firefox/) => sub ($c) {...};

generate a route with options in Mojolicious::Routes::Route, matching only OPTIONS requests. see Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information. โš™๏ธ

patch

my $route = patch '/:foo' => sub ($c) {...};
my $route = patch '/:foo' => sub ($c) {...} => 'name';
my $route = patch '/:foo' => {foo => 'bar'} => sub ($c) {...};
my $route = patch '/:foo' => [foo => qr/\w+/] => sub ($c) {...};
my $route = patch '/:foo' => (agent => qr/Firefox/) => sub ($c) {...};

generate a route with patch in Mojolicious::Routes::Route, matching only PATCH requests. see Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information. ๐Ÿฉน

plugin

plugin SomePlugin => {foo => 23};

load a plugin with plugin in Mojolicious. ๐Ÿ”Œ

post

my $route = post '/:foo' => sub ($c) {...};
my $route = post '/:foo' => sub ($c) {...} => 'name';
my $route = post '/:foo' => {foo => 'bar'} => sub ($c) {...};
my $route = post '/:foo' => [foo => qr/\w+/] => sub ($c) {...};
my $route = post '/:foo' => (agent => qr/Firefox/) => sub ($c) {...};

generate a route with post in Mojolicious::Routes::Route, matching only POST requests. see Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information. ๐Ÿ“ฎ

put

my $route = put '/:foo' => sub ($c) {...};
my $route = put '/:foo' => sub ($c) {...} => 'name';
my $route = put '/:foo' => {foo => 'bar'} => sub ($c) {...};
my $route = put '/:foo' => [foo => qr/\w+/] => sub ($c) {...};
my $route = put '/:foo' => (agent => qr/Firefox/) => sub ($c) {...};

generate a route with put in Mojolicious::Routes::Route, matching only PUT requests. see Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information. ๐Ÿ“ฅ

query

my $route = query '/:foo' => sub ($c) {...};
my $route = query '/:foo' => sub ($c) {...} => 'name';
my $route = query '/:foo' => {foo => 'bar'} => sub ($c) {...};
my $route = query '/:foo' => [foo => qr/\w+/] => sub ($c) {...};
my $route = query '/:foo' => (agent => qr/Firefox/) => sub ($c) {...};

generate a route with query in Mojolicious::Routes::Route, matching only QUERY requests. see Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information. ๐Ÿ”

under

my $route = under sub ($c) {...};
my $route = under '/:foo' => sub ($c) {...};
my $route = under '/:foo' => {foo => 'bar'};
my $route = under '/:foo' => [foo => qr/\w+/];
my $route = under '/:foo' => (agent => qr/Firefox/);
my $route = under [format => ['json', 'yaml']];

generate a nested route with under in Mojolicious::Routes::Route, to which all following routes are automatically appended. everything after this lives under it, it's giving umbrella โ˜‚๏ธ see Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information.

websocket

my $route = websocket '/:foo' => sub ($c) {...};
my $route = websocket '/:foo' => sub ($c) {...} => 'name';
my $route = websocket '/:foo' => {foo => 'bar'} => sub ($c) {...};
my $route = websocket '/:foo' => [foo => qr/\w+/] => sub ($c) {...};
my $route = websocket '/:foo' => (agent => qr/Firefox/) => sub ($c) {...};

generate a route with websocket in Mojolicious::Routes::Route, matching only WebSocket handshakes. real-time besties only ๐Ÿค see Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information. ๐ŸŒ


๐ŸŽ€ ATTRIBUTES ๐ŸŽ€

Mojolicious::Lite inherits all attributes from Mojolicious. all of them. she's generous ๐Ÿ’–


๐ŸŽ€ METHODS ๐ŸŽ€

Mojolicious::Lite inherits all methods from Mojolicious. same energy, more methods ๐Ÿ’…


โญ SEE ALSO โญ

Mojolicious, Mojolicious::Guides, <https://mojolicious.org>. go click, iykyk ๐Ÿฆ‹


that's the whole page bestie, you ate it up ๐Ÿ’€โœจ

perl v5.42.0 ยท 2026-07-15 ยท Mojolicious::Lite(3) โ€” mwah, go build something iconic ๐Ÿซถ๐Ÿ‘‘

๐Ÿ“ฆ where this page comes from