forked from planety/prologue-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.nim
27 lines (18 loc) · 896 Bytes
/
app.nim
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
import prologue
# Handlers
proc selectByParam(ctx: Context) {.async.} =
resp "This page accessed by URL param: " & ctx.getPathParams("param")
proc selectByDefaultParam(ctx: Context) {.async.} =
resp "This page accessed by URL non-existing param - using default value: " & ctx.getPathParams("non_exsiting_param", "default value")
proc selectMultipleParams(ctx: Context) {.async.} =
resp "This page accessed by multiple URL params: " & ctx.getPathParams("param_1", "default value 1") & " and " & ctx.getPathParams("param_2", "default value 2")
# Create default settings
let settings = newSettings()
# Create instance
var app = newApp(settings = settings)
# Create routes
app.addRoute("/select/{param}", selectByParam)
app.addRoute("/select-wrong/{param}", selectByDefaultParam)
app.addRoute("/select-multiple/{param_1}/{param_2}", selectMultipleParams)
# Run instance
app.run()