https://leafo.net/lapis/ Lapis Lapis A web framework for Lua v1.16.0 Reference Reference Manual Install luarocks install lapis For Lua 5.1+/LuaJIT Github Source on GitHub November 2nd, 2023: Lapis v1.16.0 -- types.params_map, improved model:update: changelog What is it? Lapis is a framework for building web applications in Lua (or MoonScript) that primarily targets OpenResty, a high performance web platform that runs on a customized version of Nginx. Lapis can also be used in other server environments, being compatible with any modern version of Lua. Want to talk Lapis? Join our Discord Lua MoonScript local lapis = require "lapis" local app = lapis.Application() app:match("/", function(self) return "Hello world!" end) return app lapis = require "lapis" class extends lapis.Application "/": => "Hello world!" How does it work? With OpenResty, Lua is run directly inside of the Nginx worker using LuaJIT, giving you the smallest barrier between the webserver and your code. Have a look at Web Framework Benchmarks just to see how OpenResty stacks up against other platforms. Utilizing the power of Lua coroutines, you can write clean code that looks synchronous but can achieve high throughput by automatically running asynchronously without blocking. Networking operations like database queries and HTTP requests will automatically yield to allow for handling concurrent requests, all without all that callback spaghetti seen in other asynchronous platforms. It's fast, easy to read, and easy to write. What does it come with? Lapis includes URL routing, HTML Templating, CSRF Protection and Session support, PostgreSQL/MySQL/SQLite backed models, schema generation and migrations in addition to a collection of useful functions needed when developing a website. Lua MoonScript local lapis = require "lapis" local app = lapis.Application() -- Define a basic pattern that matches / app:match("/", function(self) local profile_url = self:url_for("profile", {name = "leafo"}) -- Use HTML builder syntax helper to quickly and safely write markup return self:html(function() h2("Welcome!") text("Go to my ") a({href = profile_url}, "profile") end) end) -- Define a named route pattern with a variable called name app:match("profile", "/:name", function(self) return self:html(function() div({class = "profile"}, "Welcome to the profile of " .. self.params.name) end) end) return app lapis = require "lapis" class extends lapis.Application -- Define a basic pattern that matches / "/": => profile_url = @url_for "profile", name: "leafo" -- Use HTML builder syntax helper to quickly and safely write markup @html -> h2 "Welcome!" text "Go to my " a href: profile_url, "profile" -- Define a named route pattern with a variable called name [profile: "/:name"]: => @html -> div class: "profile", -> text "Welcome to the profile of ", @params.name Models Get a powerful abstraction layer over your database tables just by sub-classing Model: Lua MoonScript local Model = require("lapis.db.model").Model -- Create a model, backed by the table `users` local Users = Model:extend("users") -- fetch some rows from the table local elderly_users = Users:select("where age > ? limit 5", 10) local random_user = Users:find(1233) -- find by primary key local lee = Users:find({ name = "Lee", email = "leemiller@example.com" }) -- create a new row and edit it local user = Users:create({ name = "Leaf", email = "leaf@example.com", age = 6 }) user:update({ age = 10 }) user:delete() import Model from require "lapis.db.model" -- Create a model, automatically backed by the table `users` class Users extends Model -- fetch some rows from the table elderly_users = Users\select "where age > ? limit 5", 10 random_user = Users\find 1233 -- find by primary key lee = Users\find name: "Lee", email: "leemiller@example.com" -- create a new row and edit it user = Users\create { name: "Leaf" email: "leaf@example.com" age: 6 } user\update age: 10 user\delete! Templates Write your templates either in etlua or in pure Lua/MoonScript. The Widget base class allows you to organize your templates as modules, enabling you to use inheritance and mixins to mix and match methods combined with the HTML builder syntax that lets you express HTML with the full power of the language you're already using. The HTML builder syntax makes you immune to cross site scripting attacks from user-provided input by ensuring all written content is escaped correctly. Lua MoonScript