Skip to content

Instantly share code, notes, and snippets.

@lihaoyi
Created January 4, 2015 11:22
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 lihaoyi/89d4803da8d3f33c823a to your computer and use it in GitHub Desktop.
Save lihaoyi/89d4803da8d3f33c823a to your computer and use it in GitHub Desktop.
package com.example
import akka.actor.Actor
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
"""<html>
<body>
<h1>Say hello to <i>spray-routing</i> on <i>spray-can</i>!</h1>
</body>
</html>"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment