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: 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
Throws
Error: type mismatch: got <Table[system.string, proc (request:
Request){.cdecl.}], string, proc (request: Request){.cdecl.}>
Run