Scala syntax issue: / and ~

Can someone help me, and explain what is :/ and then ~ in scala, for example:

 json = http(:/("api.twitter.com") / "1/users/show.json" <<? Map("screen_name" -> "aloiscochard") >~ { _.getLines.mkString }) 

from: http://aloiscochard.blogspot.com/2011/05/simple-rest-web-service-client-in-scala.html

+4
source share
1 answer

In the code you are referring to, pay attention to import dispatch._ . This imports the distribution library .

In this library, we find an object :/ that has an apply method, so that means :/("api.twitter.com") .

In addition, the code does not have ~ , or only << 24>. In Scala, any group of characters is the name of a method that can be used as an operator. Therefore >~ should be a method for something.

Looking around, we find that HandlerVerbs defines a >~ method that will "handle the response as scala.io.Source in a block".

To understand what the code does in detail, you need to understand the dispatch library, which I do not do.

This library seems to be a very heavy DSL. Thus, it can be a great choice if you do a lot and a lot of sending work (because the distribution, I hope, can be done in an intuitive and clean way). But this can be a terrible choice for a one-time use, as you must know the library well to understand what it can do (due to the choice of very short method names such as >~ ).

+8
source

All Articles