Skip to content

Instantly share code, notes, and snippets.

Created January 4, 2015 11:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
package com.example
import spray.routing._
import spray.http._
import MediaTypes._
// we don't implement our route structure directly in the service actor because
// we want to be able to test it independently, without having to spin up an actor
class MyServiceActor extends Actor with MyService
// the HttpService trait defines only one abstract member, which
// connects the services environment to the enclosing actor or test
def actorRefFactory = context
// this actor only runs our route, but you could add
// other things here, like request stream processing
// or timeout handling
def receive = runRoute(myRoute)
// this trait defines our service behavior independently from the service actor
trait MyService extends HttpService
val myRoute =
path("") do
get do
respondWithMediaType(`text/html`) do // XML is marshalled to `text/xml` by default, so we simply override here
complete do
<h1>Say hello to <i>spray-routing</i> on <i>spray-can</i>!</h1>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment