0

I'm about to set up a stupid play/scala app whose only job will be to make some http call once it receives calls itself

GET /abracadabra controllers.Application.abracadabra(stuff: String)

and then

      def abracadabra(stuff: String) = Action {
        Logger.info("called for stuff: "+stuff);
            // call this other URL with 'stuff' as get parameter
            // log http return status code and return Ok/200 anyways
      }

Now for the second (commented) part I thought about using Dispatch.

I've read the docs but I can't just figure out how to use Promises and all that.

If anybody could point me to some sample code or something, it will be much appreciated

Urist McDev
  • 498
  • 3
  • 14
mfirry
  • 3,634
  • 1
  • 26
  • 36
  • I give a basic Dispatch 0.9 example [here](http://stackoverflow.com/a/12343111/334519). If you're using Play, though, you may be better off with the [WS library](https://github.com/playframework/Play20/wiki/ScalaWS). – Travis Brown Sep 19 '12 at 11:52

1 Answers1

1

Since Play! has a built in Async library, you should probably go ahead and use that unless there's a feature in Dispatch that you specifically need.

Here's a short example:

def abracadabra(stuff: String) = Action {
  Logger.info("called for stuff: "+stuff);
  Async {
    WS.url("http://stackoverflow.com/").get().map { response =>
      Ok("I got it: " + response)
    }
  }  
}

The documentation is here: https://github.com/playframework/Play20/wiki/ScalaWS

Andrew Conner
  • 1,436
  • 13
  • 21
  • Thanks @Travis Brown and andrew. You both were helpful. I'm new to scalaDoc and play, so I'm figuring out how to handle option http method too. – mfirry Sep 19 '12 at 13:13