使用 spray.io 来自服务器的多个响应

multiple responses from server using spray.io

我正在使用喷雾 api。我有以下代码:

  import akka.actor.ActorSystem
  import spray.routing.SimpleRoutingApp
  import spray.json.DefaultJsonProtocol._
  object Server1 extends App with SimpleRoutingApp{
        implicit val actorSystem = ActorSystem()   
        startServer(interface="localhost",port = 8080){
        println("Listening...")    
        get{
            println("incoming..")
            path("state"){
                 complete{
                     "in the complete block"             
                 }     
            } 
        }
    }
 }

它在 api 上给出了一个响应。当我从网络浏览器调用时,它会打印 "in the complete block" 。我可以让它迭代意味着我使用一个变量并在完整块中发送它的值然后我可以更改该变量的值然后在完整块中发送它的新值。

你的意思是这样的:

        var state = 0
        get{
            println("incoming..")
            path("state"){
                 complete{
                     state = state + 1
                     s"in the complete block ${state}"             
                 }     
            } 
        }