我在 Spray 中有以下代码来解析用户调用的 REST 服务:
val route = {
pathPrefix("v0") {
pathPrefix("pets") {
pathEndOrSingleSlash {
pathEnd {
get {
complete("/v0/pets")
}
} ~
get {
complete("/v0/pets/")
}
} ~
parameters('id ?) {
id =>
get {
complete("/v0/pets?id=" + id)
}
}
}
}
}
问题是它的行为不符合预期。我期待代码中的以下行为:
http://127.0.0.1/v0/pets => /v0/pets
http://127.0.0.1/v0/pets/ => /v0/pets/
http://127.0.0.1/v0/pets?id=1234 = > /v0/pets?id=Some(1234)
但是,我得到以下查询结果:
http://127.0.0.1/v0/pets => /v0/pets
http://127.0.0.1/v0/pets/ => /v0/pets
http://127.0.0.1/v0/pets?id=1234 => /v0/pets