Skip to content

Instantly share code, notes, and snippets.

@plaflamme
Created March 21, 2012 02:37
Show Gist options
  • Save plaflamme/2143869 to your computer and use it in GitHub Desktop.
Save plaflamme/2143869 to your computer and use it in GitHub Desktop.
package com.example
import cc.spray._
import cc.spray.directives.IntNumber
trait HelloService extends Directives {
val helloService = {
path("") {
get { _.complete("Say hello to Spray!") }
} ~
pathPrefix("contact" / IntNumber) { id =>
contactService(id)
}
}
def contactService(id: Int): Route =
path("") {
get {
completeWith {
"Contact #" + id
}
}
} ~ pathPrefix("bills/latest") {
billService(id + 42)
}
def billService(id: Int): Route =
path("") {
get {
completeWith {
"Bill #" + id
}
} ~
delete {
completeWith {
"Deleted bill #" + id
}
}
} ~
pathPrefix("contact") { ctx => // Need this otherwise we get an infinite recursion
contactService(66)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment