Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rust-swerve
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Louis
rust-swerve
Commits
e3108a4b
Commit
e3108a4b
authored
6 years ago
by
Louis
Browse files
Options
Downloads
Patches
Plain Diff
Add example with more complex lua logic and multiple route params
parent
af7bb8f2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
Loading
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
example/.swerve/accounts/handle_widgets.lua
+39
-0
39 additions, 0 deletions
example/.swerve/accounts/handle_widgets.lua
example/.swerve/config.yml
+2
-0
2 additions, 0 deletions
example/.swerve/config.yml
with
41 additions
and
0 deletions
example/.swerve/accounts/handle_widgets.lua
0 → 100644
+
39
−
0
View file @
e3108a4b
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
This diff is collapsed.
Click to expand it.
example/.swerve/config.yml
+
2
−
0
View file @
e3108a4b
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment