Trying Netty

As with the Jetty server used for earlier console hacking, for Netty we also need a starter project. If you don’t have the g8 command line tool installed, please go back to that page until you do.

Enter the Console

This step will fetch a number of dependencies and sometimes certain repositories are a little wonky, so cross your fingers.

g8 unfiltered/unfiltered-netty --name=nettyplayin
cd nettyplayin
sbt console

Once you do get to a console, this should just work:

import unfiltered.response._
val hello = unfiltered.netty.cycle.Planify {
  case _ => ResponseString("hello world")
}
unfiltered.netty.Server.http(8080).plan(hello).run()

Direct a web browser to http://127.0.0.1:8080/ and you’ll be in hello world business.

The source code for this page can be found here.