Created
February 19, 2012 21:30
-
-
Save andypetrella/1865900 to your computer and use it in GitHub Desktop.
Dispatch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
url(urlString) | |
>\ "ISO-8859-1" //set the charset | |
<:< (Map("Accept-Language" -> "fr-BE" )) //set some headers | |
gzip //encode the response in archived gzip is accepted |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dispatch._ | |
val http = new Http | |
http(:/("localhost", 7474) / "db" / "data") //ok now what to do with the result... here come the Handlers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val h = new Html | |
h(url(urlString) >| ) // the simpler, it ignores the content | |
h(url(urlString) <> { xml => //do something with xml } ) // this handler converts to xml | |
h(url(urlString) >- { txt => //do something with txt } ) // this handler converts to txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
url(urlString) POST | |
url(urlString) PUT | |
url(urlString) DELETE | |
url(urlString) HEAD |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
url(urlString) << (bodyAsStringOrTupleOfStrings) // Two "less than"s will POST with the body as payload | |
url(urlString) <<< (bodyAsStringOrTupleOfStrings) // Three "less than"s will PUT with the body as payload | |
url(urlString) <<? (tupleOfStrings) // the payload will be generated as query parameters |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:/("dispatch.databinder.net", 80) / "URLs+and+Paths" //note that the port can be omitted | |
url("http://dispatch.databinder.net/URLs+and+Paths") // pretty simple, if the root is already a path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment