-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapp.nim
51 lines (35 loc) · 905 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import std/with
import prologue
# App instance
var app = newApp()
# Nesting
var base = newGroup(app, "/apiv2", @[])
var level1 = newGroup(app,"/level1", @[], base)
var level2 = newGroup(app, "/level2", @[], level1)
# Handlers
proc hello(ctx: Context) {.async.} =
resp "Hello"
proc hi(ctx: Context) {.async.} =
resp "Hi"
# Routes
with base:
get("/hello", hello)
get("/hi", hi)
with level1:
get("/hello", hello)
get("/hi", hi)
with level2:
get("/hello", hello)
get("/hi", hi)
app.run()
#[
URLs for base are:
- http://127.0.0.1:8080/apiv2/hello
- http://127.0.0.1:8080/apiv2/hi
URLs level 1 are:
- http://127.0.0.1:8080/apiv2/level1/hello
- http://127.0.0.1:8080/apiv2/level1/hi
URLs for level 2 are:
- http://127.0.0.1:8080/apiv2/level1/level2/hello
- http://127.0.0.1:8080/apiv2/level1/level2/hi
]#