Rosencrantz是路由删除方法不起作用吗?

时间:2019-05-17 01:22:39

标签: nim

我使用Rosencrantz到Api服务器。
但是
运行DELETE方法集编译为错误
不工作吗?

i将文档副本和路径,消息,http方法更改为“仅编辑”

nim versin:0.19.6
rosencrantz:0.3.8

import
  asyncdispatch,
  asynchttpserver,
  strutils,
  rosencrantz

let handler = get[
  path("/api/users")[
    ok("Get Users")
  ] ~
  pathChunk("/api/users")[
    intSegment(proc(id: int): auto =
      ok("Get User by " & intToStr(id) & "!")
    )
  ]
] ~ delete[
  pathChunk("/api/users")[
    intSegment(proc(id: int): auto =
      ok("Delete User by " & intToStr(id) & "!")
    )
  ]
]

let server = newAsyncHttpServer()
waitFor server.serve(Port(8080), handler)

错误消息

     :
     :
    ... api.nim(16, 3) Error: type mismatch: got <Handler, proc (x: var seq[Handler], i: Natural){.noSideEffect, gcsafe, locks: 0.}>
    ... but expected one of:
    ... proc `~`(h1, h2: Handler): Handler
    ...   first type mismatch at position: 2
    ...   required type: Handler
    ...   but expression 'delete' is of type: proc (x: var seq[Handler], i: Natural){.noSideEffect, gcsafe, locks: 0.}
    ... expression: (get ->
    ...     (path("/api/users") -> ok("Get Users")) ~
    ...     (pathChunk("/api/users") ->
    ...     intSegment(proc (id: int): auto = result = ok(
    ...     `&`("Get User by ", intToStr(id, 1), "!"))))) ~ delete

1 个答案:

答案 0 :(得分:0)

您必须符合delete方法的要求:

] ~ rosencranz.delete[
  pathChunk("/api/users")[
    intSegment(proc(id: int): auto =
      ok("Delete User by " & intToStr(id) & "!")
    )
  ]

或者您将呼叫system.delete