forked from planety/prologue-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.nim
31 lines (23 loc) · 797 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
import prologue
# Routes handler
proc echoMethod(ctx: Context) {.async.} =
resp "Hey! Selected method is : " & $ctx.request.reqMethod
# Create default settings
let settings = newSettings()
# Create instance
var app = newApp(settings = settings)
# Create routes
app.addRoute("/get", echoMethod, HttpGet)
app.addRoute("/post", echoMethod, HttpPost)
app.addRoute("/put", echoMethod, HttpPut)
app.addRoute("/patch", echoMethod, HttpPatch)
app.addRoute("/delete", echoMethod, HttpDelete)
app.addRoute("/any", echoMethod, @[HttpGet, HttpPost, HttpPut, HttpPatch, HttpDelete])
# alternative way
app.get("/alt-get", echoMethod)
app.post("/alt-post", echoMethod)
app.put("/alt-put", echoMethod)
app.patch("/alt-patch", echoMethod)
app.delete("/alt-delete", echoMethod)
# Run instance
app.run()