import net
import strutils
import tables
import asynchttpserver, asyncdispatch
type Server* = object
port: int
routes: Table[string, Table[string, proc(request: Request) {.cdecl.}]]
allowedMethods: seq[string]
proc newServer*: Server =
Hi! httpMethod is string here
What I need is
{
"GET": {
"/path1": handler1,
"/path2": handler2
},
"POST": {
"/path3": handler3,
"/path4": handler4
}
}
Run
type Server* = object
port: int
routes: Table[string, Table[string, proc(request: Request) {.cdecl.}]]
allowedMethods: seq[string]
proc newServer*: Server =
result.port = 8080
result.allowedMethods = @["GET", "POST"]
result.routes = initTable
proc addRoute*(self: Server, httpMethod, route: string, handler:
proc(request: Request) {.cdecl.}) =
discard
Run
Well, it works, thanks :)
proc addRoute*(self: Server, httpMethod, route: string, handler: ???)
discard
Run
What type do I need to set to pass the procedure as a handler?