diff --git a/example/.swerve/accounts/handle_widgets.lua b/example/.swerve/accounts/handle_widgets.lua new file mode 100644 index 0000000000000000000000000000000000000000..776787f46367ee4e4f74304aac62b5731cc7e367 --- /dev/null +++ b/example/.swerve/accounts/handle_widgets.lua @@ -0,0 +1,39 @@ +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 diff --git a/example/.swerve/config.yml b/example/.swerve/config.yml index 2b85e70b1569b76425d6eedc510310a3ec97d8fa..4b11c67a8af11977f72a1c126b66262458a6d821 100644 --- a/example/.swerve/config.yml +++ b/example/.swerve/config.yml @@ -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