Skip to content

Instantly share code, notes, and snippets.

@takezoe
Created December 9, 2011 02:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takezoe/1449859 to your computer and use it in GitHub Desktop.
Save takezoe/1449859 to your computer and use it in GitHub Desktop.
XML response with Unfiltered
import unfiltered.request._
import unfiltered.response._
import scala.xml._
case class Xml(nodes: NodeSeq)
extends ComposeResponse(TextXmlContent ~> ResponseString(nodes.toString))
// Usage
def intent = {
case GET(Path(Seg("hello" :: name :: Nil))) => {
Ok ~> Xml(<hello>{name}</hello>)
}
}
@takezoe
Copy link
Author

takezoe commented Dec 9, 2011

I couldn't find a case class to response XML in the Unfiltered librariy.
It might be good if classes such as this example are included in the Unfiltered library.

@xuwei-k
Copy link

xuwei-k commented Dec 9, 2011

https://github.com/unfiltered/unfiltered/blob/0.5.3/library/src/main/scala/response/writers.scala#L17-18

名前は Html だけれども、結局 scala.xml.NodeSeq 型でつまり xml だからこれでいいんじゃないですかね?

あ、でも type 違うのか・・・

@takezoe
Copy link
Author

takezoe commented Dec 9, 2011

これだと中でHtmlContentがチェインされているのでContent-Typeがtext/htmlになってしまうのです…。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment