Skip to content

Instantly share code, notes, and snippets.

@ppurang
Created May 15, 2013 11:08
Show Gist options
  • Save ppurang/5583220 to your computer and use it in GitHub Desktop.
Save ppurang/5583220 to your computer and use it in GitHub Desktop.
Simple HttpService using spray with a marshaller
trait Entry extends HttpService {
val entry = path("") {
get {
complete {
Link("order", "http://localhost:8080/order", "*/*,plain/text,application/json")
}
}
}
}
implicit val LinkMarshaller = Marshaller.of[Link](`text/plain`, `application/json`) {
(value, contentType, ctx) => contentType match {
case x if x.value.startsWith("application/json") => {
ctx.marshalTo(HttpBody(contentType, write(value)))
}
case _ => {
ctx.marshalTo(HttpBody(contentType, value.toString))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment