Skip to content

Instantly share code, notes, and snippets.

@enotodden
Last active December 19, 2015 04:28
Show Gist options
  • Save enotodden/5896849 to your computer and use it in GitHub Desktop.
Save enotodden/5896849 to your computer and use it in GitHub Desktop.
Example of routes with Turbo.
local turbo = require("turbo")
local IndexHandler = class("IndexHandler", turbo.web.RequestHandler)
function IndexHandler:get()
self:write("Index..")
end
local UserHandler = class("UserHandler", turbo.web.RequestHandler)
function UserHandler:get(username)
self:write("Username is " .. username)
end
local AddHandler = class("AddHandler", turbo.web.RequestHandler)
function AddHandler:get(a1, a2)
self:write("Result is: " .. tostring(a1+a2))
end
local application = turbo.web.Application:new({
-- No arguments, will work for 'localhost:8888' and 'localhost:8888/'
{"/$", IndexHandler},
-- Use the part of the url after /user/ as the first argument to
-- UserHandler:get
{"/user/(.*)$", UserHandler},
-- Find two int's separated by a '/' after /add in the url
-- and pass them as arguments to AddHandler:get
{"/add/(%d+)/(%d+)$", AddHandler}
})
application:listen(8888)
turbo.ioloop.instance():start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment