Skip to content

Instantly share code, notes, and snippets.

@andypetrella
Created February 19, 2012 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andypetrella/1865900 to your computer and use it in GitHub Desktop.
Save andypetrella/1865900 to your computer and use it in GitHub Desktop.
Dispatch
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
import dispatch._
val http = new Http
http(:/("localhost", 7474) / "db" / "data") //ok now what to do with the result... here come the Handlers
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
url(urlString) POST
url(urlString) PUT
url(urlString) DELETE
url(urlString) HEAD
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
:/("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