-- helloworld.lua
local turbo = require "turbo"
local MyApp = class("MyApp",
turbo.web.RequestHandler)
function MyApp:get()
self:write("Hello World!")
end
turbo.web.Application({
{"^/$", MyApp}
}):listen(8888)
turbo.ioloop.instance():start()
Create apps
Turbo provides you with all the stuff you need to develop fast web apps, web API's and networking applications.
Web application classes are modeled after the intuitive Google Webapp framework, you should quickly feel right at home.
The rest of the API's of the framework is very close to that of Python's Tornado framework.
Efficiency
LuaJIT is a Just-In-Time Compiler (JIT) for the Lua programming language being used by the complete Turbo framework. This means that your code is optimized and compiled for the native architecture it runs on, thereby reducing hardware requirements (or pay-per-use CPUs) compared to other frameworks (such as Django or Tornado).
Great for reducing your costs, power usage and producing a smaller impact on the environment.
Interactive mode
When developing your app you get good feedback on what is going on directly in your shell.
[S 2014/04/13 16:08:37] [web.lua] 200 OK GET / (127.0.0.1) 0ms
-- websocket.lua
_G.TURBO_SSL = true
local turbo = require "turbo"
local WSExHandler = class("WSExHandler",
turbo.websocket.WebSocketHandler)
function WSExHandler:on_message(msg)
self:write_message("Hello World.")
end
turbo.web.Application({
{"^/ws$", WSExHandler}
}):listen(8888)
turbo.ioloop.instance():start()
WebSockets
Create rich apps using WebSockets. The WebSockets handler provides a simple API and blends nicely in together with your other HTTP handlers.
A WebSocket client is also available and reuses the same API as its server equivalent.
Coroutines
Lua has built-in coroutines. This makes it possible to yield a request at a certain point waiting for something to finish (e.g a database lookup) and resume the function (coroutine) at that point with the results delivered in a variable. This means NO callbacks are required for async operations.
-- redis.lua
-- pseudo code
function MyApp:get(id)
local val = coroutine.yield(redis:get(id))
self:write({result = val})
end
-- githubfeed.lua
-- Fetch number of watchers of the Turbo repo and
-- render using Mustache templates.
local templates = turbo.web.Mustache.TemplateHelper(
"/var/templates/")
function GithubFeed:get(search)
local res = coroutine.yield(
turbo.async.HTTPClient():fetch(
"https://api.github.com/repos/kernelsauce/turbo"))
if res.error or res.headers:get_status_code() ~= 200 then
-- Check for errors.
-- If data could not be fetched a 500 error is
-- sent as response.
error(turbo.web.HTTPError(500, res.error.message))
end
local json = turbo.escape.json_decode(res.body)
self:write(templates:render("github.mustache", json))
end
local application = turbo.web.Application({
{"^/$", GithubFeed}
})
Batteries included
Many features are included in the Turbo framework. Such as a async HTTP client, a file server, JSON parsing and serialization, Mustache parsers, SSL, hash, escaping, filesystem functions and more. Most things required by a modern web and networking apps are included. All utility features are of high quality and has been optimized for speed.
Create a app using the GitHub API quickly using the HTTP client, JSON parser and Mustache for HTML rendering.
Examples
Review example code included. There are many examples displaying the different features.
There is also a extensive test suite of the framework included which also demonstrates some possiblites you have when coding.
Docs
Extensive documentation of the complete framework is available and up-to-date. The documentation is generated from rst (ReStructuredText) files.
