Giter Site home page Giter Site logo

lor's Introduction

Lor

https://travis-ci.org/sumory/lor.svg?branch=master

Lor是一个运行在OpenResty上的基于Lua编写的Web框架.

  • 路由采用Sinatra风格,Sinatra是Ruby小而精的web框架.
  • API基本采用了Express的思路和设计,Node.js跨界开发者可以很快上手.
  • 支持插件(middleware),路由可分组,路由匹配支持string/正则模式.
  • lor以后会保持核心足够精简,扩展功能依赖middleware来实现. lor本身也是基于middleware构建的.
  • 推荐使用lor作为HTTP API Server,lor也已支持session/cookie/html template等功能.
  • 框架文档在这里,正在逐步完善.

当前版本:v0.0.4,下一版本v0.0.5计划:

  • 完善文档,补充用例

快速开始

在使用lor之前请首先确保OpenResty和luajit已安装.

一个简单示例,更复杂的示例或项目模板请使用lord命令生成:

local lor = require("lor.index")
local app = lor()

app:get("/", function(req, res, next)
    res:send("hello world!")
end)

-- 路由示例: 匹配/query/123?foo=bar
app:get("/query/:id", function(req, res, next)
    local foo = req.query.foo -- 从url queryString取值:"bar"
    local path_id = req.params.id -- 从path取值:"123"
    res:json({
        foo = foo,
        id = path_id
    })
end)

-- 404 error
app:use(function(req, res, next)
    if req:isFound() ~= true then
        res:status(404):send("sorry, not found.")
    end
end)

-- 错误处理插件,可根据需要定义多个
app:erroruse(function(err, req, res, next)
    -- err是错误对象
    res:status(500):send("服务器内发生未知错误")
end)

安装

使用install.sh安装lor框架

#如把lor安装到/opt/lua/lor目录下
sh install.sh /opt/lua/lor 

执行以上命令后lor的命令行工具lord就被安装在了/usr/local/bin下, 通过which lord查看:

$ which lord
/usr/local/bin/lord

lor的运行时包安装在了/opt/lua/lor下, 通过ll /opt/lua/lor查看:

$ ll /opt/lua/lor
total 56
drwxr-xr-x  14 root  wheel   476B  1 22 01:18 .
drwxrwxrwt  14 root  wheel   476B  1 22 01:18 ..
-rw-r--r--   1 root  wheel     0B  1 19 23:48 CHANGELOG.md
-rw-r--r--   1 root  wheel   1.0K  1 19 23:48 LICENSE
-rw-r--r--   1 root  wheel     0B  1 19 23:48 Makefile
-rw-r--r--   1 root  wheel   1.9K  1 21 20:59 README-zh.md
-rw-r--r--   1 root  wheel   870B  1 21 20:59 README.md
drwxr-xr-x   4 root  wheel   136B  1 22 00:06 bin
-rw-r--r--   1 root  wheel   1.6K  1 19 23:48 install.md
-rw-r--r--   1 root  wheel   1.0K  1 21 22:37 install.sh
drwxr-xr-x   4 root  wheel   136B  1 21 22:40 lor
drwxr-xr-x  13 root  wheel   442B  1 22 01:17 test

至此, lor框架已经安装完毕,接下来使用lord命令行工具快速开始一个项目.

使用

$ lord -h
lor v0.0.4, a Lua web framework based on OpenResty.

Usage: lor COMMAND [OPTIONS]

Commands:
 new [name]             Create a new application
 start                  Starts the server
 stop                   Stops the server
 restart                Restart the server
 version                Show version of lor
 help                   Show help tips

Options:
 --debug                Show some runtime details

执行lord new lor_demo,则会生成一个名为lor_demo的示例项目,然后执行:

cd lor_demo
lord start

之后访问http://localhost:8888/,即可。

更多使用方法,请参考test测试用例。

讨论交流

目前有一个QQ群用于在线讨论:QQ群522410959 522410959

License

MIT

lor's People

Contributors

sumory avatar lihuibin avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.