Scala Akka如何基于参数值有条件向前请求
我有一条与此类似的现有路线:Scala Akka如何基于参数值有条件向前请求,scala,akka,akka-http,Scala,Akka,Akka Http,我有一条与此类似的现有路线: pathPrefix("foo") { pathPrefix(IntNumber) { id => post { entity(as[FooReqeust]) { request => val f = doSomething(id, request) onComplete(f) { case Success(res) => complete(res) c
pathPrefix("foo") {
pathPrefix(IntNumber) { id =>
post {
entity(as[FooReqeust]) { request =>
val f = doSomething(id, request)
onComplete(f) {
case Success(res) => complete(res)
case Failure(e) => complete(HttpResponse(InternalServerError, entity = "someError"))
}
}
}
}
}
我们有一个新的服务(此服务的外部),我们希望在运行一些测试后,在将来开始路由到该服务。新的服务标题/参数/帖子正文等与现有的相同
如果id
满足某些条件,我希望将现有端点的请求转发到新端点
我不清楚该怎么做。(并希望避免序列化/反序列化检查主体等)
例如:
pathPrefix("foo") {
pathPrefix(IntNumber) { id =>
post {
if (id == 1234) complete(usingNewService(...)) <<<< blindly complete with the new service
else // use the current implementation
entity(as[FooReqeust]) { request =>
.... same code as before ...
}
}
}
}
路径前缀(“foo”){
路径前缀(IntNumber){id=>
职位{
如果(id==1234)完成(使用NewService(…),您可以使用临时重定向,即307状态代码,并使客户端对新服务重新执行请求吗?重定向是什么意思?Http或转发调用(如果端点可用,这很容易)?向客户端发送代码为307的http响应,以执行对不同端点的调用,因为`新服务头/参数/post正文等与现有的`对不起,我的坏消息,请求是post,无法重定向在此将问题更新为“转发请求”