1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#!/usr/bin/env lua
--- A simple LuaRocks mock-server for testing.
local restserver = require("restserver")
local server = restserver:new():port(8080)
server:add_resource("api/tool_version", {
{
method = "GET",
path = "/",
produces = "application/json",
handler = function(query)
local json = { version = query.current }
return restserver.response():status(200):entity(json)
end
}
})
server:add_resource("api/1/{id:[0-9]+}/status", {
{
method = "GET",
path = "/",
produces = "application/json",
handler = function(query)
local json = { user_id = "123", created_at = "29.1.1993" }
return restserver.response():status(200):entity(json)
end
}
})
server:add_resource("/api/1/{id:[0-9]+}/check_rockspec", {
{
method = "GET",
path = "/",
produces = "application/json",
handler = function(query)
local json = {}
return restserver.response():status(200):entity(json)
end
}
})
server:add_resource("/api/1/{id:[0-9]+}/upload", {
{
method = "POST",
path = "/",
produces = "application/json",
handler = function(query)
local json = {module = "luasocket", version = {id = "1.0"}, module_url = "http://localhost/luasocket", manifests = "root", is_new = "is_new"}
return restserver.response():status(200):entity(json)
end
}
})
server:add_resource("/api/1/{id:[0-9]+}/upload_rock/{id:[0-9]+}", {
{
method = "POST",
path = "/",
produces = "application/json",
handler = function(query)
local json = {"rock","module_url"}
return restserver.response():status(200):entity(json)
end
}
})
-- SHUTDOWN this mock-server
server:add_resource("/shutdown", {
{
method = "GET",
path = "/",
handler = function(query)
os.exit()
return restserver.response():status(200):entity()
end
}
})
-- This loads the restserver.xavante plugin
server:enable("restserver.xavante"):start()
|