0
votes

I am working with the spray api. I have the following code:

  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"             
                 }     
            } 
        }
    }
 }

It is giving a single response on api. It will print "in the complete block" when i call from web browser. Can I make it iterative means that i use a variable and send its value in complete block then I can change the value of that variable and then send its new value in complete block.

1

1 Answers

1
votes

You mean something like this:

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