Skip to content
Snippets Groups Projects
Commit e3108a4b authored by Louis's avatar Louis :fire:
Browse files

Add example with more complex lua logic and multiple route params

parent af7bb8f2
No related branches found
No related tags found
Loading
local accountDB = {}
accountDB['fancy-account'] = {
name = "Fancy Account",
widgets = { barfoo = "The best widget in town", bipbop = "A really good widget"}
}
accountDB['less-fancy-account'] = {
name = "Not Quite As Fancy Account",
widgets = { cooliowidget = "A really good widget that should be respected" }
}
accountDB['unrelated-account'] = {
name = "John Mysterio's Vault of Wonders",
widgets = { yes = "You buy widget, yes?", widget = "Widget is good!", flubber = "Green, Ready to Rock" }
}
account = accountDB[params.account_id]
res = empty_response()
res:set_header('Content-Type', 'application/json')
print("[WIDGETS] Looking for:", params.account_id, params.widget_id)
if not (account == nil) then
print("[WIDGETS] Found", account.name)
local widget = account.widgets[params.widget_id]
if not (widget == nil) then
res:set_status(200)
res:set_body(json_encode({ widget = widget }))
else
res:set_status(404)
res:set_body(json_encode({ message = "Could not find widget" }))
end
else
res:set_status(404)
res:set_body(json_encode({ message = "Could not find account" }))
end
return res
......@@ -5,6 +5,8 @@ server:
routes:
- route: /users/@user_id
script: get_user.lua
- route: /accounts/@account_id/widgets/@widget_id
script: accounts/handle_widgets.lua
- route: /users
response:
failure_rate: 5
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment