【发布时间】:2015-10-25 20:15:54
【问题描述】:
在这里回答我自己的问题,因为我花了一天多的时间才弄清楚,这是一个非常简单的问题,我认为其他人可能会遇到。
在使用 Spray 创建的 RESTful-esk 服务时,我想匹配路径中包含字母数字 id 的路由。这是我最初的开始:
case class APIPagination(val page: Option[Int], val perPage: Option[Int])
get {
pathPrefix("v0" / "things") {
pathEndOrSingleSlash {
parameters('page ? 0, 'perPage ? 10).as(APIPagination) { pagination =>
respondWithMediaType(`application/json`) {
complete("things")
}
}
} ~
path(Segment) { thingStringId =>
pathEnd {
complete(thingStringId)
} ~
pathSuffix("subthings") {
pathEndOrSingleSlash {
complete("subthings")
}
} ~
pathSuffix("othersubthings") {
pathEndOrSingleSlash {
complete("othersubthings")
}
}
}
}
} ~ //more routes...
而且这编译没有问题,但是当使用scalatest验证路由结构是否正确时,我惊讶地发现这种类型的输出:
"ThingServiceTests:"
"Thing Service Routes should not reject:"
- should /v0/things
- should /v0/things/thingId
- should /v0/things/thingId/subthings *** FAILED ***
Request was not handled (RouteTest.scala:64)
- should /v0/things/thingId/othersubthings *** FAILED ***
Request was not handled (RouteTest.scala:64)
我的路线有什么问题?
【问题讨论】: