Try Dispatch

Getting a Console

The simplest way to try Dispatch is to clone the Twine example application from github.

git clone

If you don’t have git available, you can download and extract the project’s current zip archive.

Twine is built with sbt 0.10. If you haven’t yet setup sbt, now is a good time to do that. Once you have sbt on your executable search path, you can enter its interactive console for the Twine project.

cd dispatch-twine

In sbt’s console, call the console task.


On the first run this task will download Dispatch dependencies and compile the Twine app. After that, you should see a message welcoming you to the console and a friendly scala> prompt.

Your First Request

First, import the main Dispatch classes and objects into scope.

import dispatch._

Then, we’ll need an HTTP executor to carry out our requests.

val h = new Http

Requests are described with dispatch.Request objects, and one way to construct them is with a URL.

val req = url("")

This works because you’ve imported an object called url from the dispatch package, and the object is itself a function that creates request objects.

Now, we have an executor and a request. Dispatch needs to know how to handle the request.

val handler = req >>> System.out

With this complete request-response handler, Dispatch can execute the request. Assuming you have a network connection, that is.


And that was the source of the Scala home page. Of course, we don’t usually assign all these component parts to values unless we need to reuse them. Typically, the handler above would be written in one line.

h(url("") >>> System.out)

If you can’t wait to see more Dispatch verbs like >>>, here’s a colorful cheat sheet.

Fork me on GitHub