This compiles:
import tables, asynchttpserver
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[string, Table[string, proc(request: Request)
{.cdecl.}]]()
proc addRoute*(self: var Server, httpMethod, route: string, handler:
proc(request: Request) {.cdecl.}) =
if self.routes.hasKey(httpMethod):
self.routes[httpMethod][route] = handler # Error here before
[route]
else:
self.routes[httpMethod] = {route: handler}.toTable
Run
You might want to look into "jester" though.