【问题标题】:multiple responses from server using spray.io使用 spray.io 来自服务器的多个响应
【发布时间】:2015-12-15 05:34:45
【问题描述】:

我正在使用喷雾 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 上给出一个单一的响应。当我从网络浏览器调用时,它将打印“完整块”。我可以让它迭代意味着我使用一个变量并在完整块中发送它的值然后我可以更改该变量的值然后在完整块中发送它的新值。

【问题讨论】:

    标签: scala spray


    【解决方案1】:

    你的意思是这样的:

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

    【讨论】:

      猜你喜欢
      • 2011-01-26
      • 2023-04-11
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-20
      • 1970-01-01
      相关资源
      最近更新 更多