Lor

一个基于OpenResty的高性能Web/API开发框架

v0.3.1

开始使用 Github

高性能

运行在OpenResty上, 可充分使用Nginx/OpenResty的库和插件

易开发

使用Lua作为主要编码语言, 开发效率可媲美PHP等传统Web开发语言

低门槛

采用简单易用的Sinatra风格路由, 并提供丰富的中间件功能

Hello World!

local lor = require("lor.index")
local app = lor()
app:get("/", function(req, res, next)
res:send("hello world!")
end)
app:run()

RESTful Example

local lor = require("lor.index")
local app = lor()
local userRouter = lor:Router()
userRouter:get("/find/:id", function(req, res, next)
local query_id = tonumber(req.params.id)
res:render("user/info", {
id = query_id,
name = "user" .. query_id,
})
end)
userRouter:delete("/delete", function(req, res, next)
local id = req.query.id
res:html("<span>succeed to delete user</span>")
end)
userRouter:put("/modify/:id", function(req, res, next)
local id = req.params.id
local new_name = req.query.new_name
res:send("succeed to modify user[" .. id .. "]")
end)
userRouter:post("/create", function(req, res, next)
local id = req.body.id
local name = req.body.name
return res:json({
success = true,
msg = "succeed to create new user."
})
end)
app:use("user", userRouter())
app:get("/", function(req, res, next)
res:send("Hello world!")
end)
app:erroruse(function(err, req, res, next)
if req:is_found() ~= true then
res:status(404):send("404! page not found!")
else
ngx.log(ngx.ERR, err)
res:status(500):send("unknown error")
end
end)
app:run()
了解更多