nim-json-rpc/json_rpc/server.nim
Jacek Sieka 64d40d6c1a
simplify imports (#98)
remove broken uint64 converter - upstream std/json also includes a
broken uint64 converter
2021-03-26 13:17:00 +01:00

37 lines
917 B
Nim

import
chronos,
./router,
./jsonmarshal
export chronos, jsonmarshal, router
type
RpcServer* = ref object of RootRef
router*: RpcRouter
proc new(T: type RpcServer): T =
T(router: RpcRouter.init())
proc newRpcServer*(): RpcServer {.deprecated.} = RpcServer.new()
template rpc*(server: RpcServer, path: string, body: untyped): untyped =
server.router.rpc(path, body)
template hasMethod*(server: RpcServer, methodName: string): bool =
server.router.hasMethod(methodName)
# Wrapper for message processing
proc route*(server: RpcServer, line: string): Future[string] {.gcsafe.} =
server.router.route(line)
# Server registration
proc register*(server: RpcServer, name: string, rpc: RpcProc) =
## Add a name/code pair to the RPC server.
server.router.register(name, rpc)
proc unRegisterAll*(server: RpcServer) =
# Remove all remote procedure calls from this server.
server.router.clear