Scala Lift: How to wrap REST responses into an XML root element?
I'm doing a project to test Scala and Lift at my c开发者_如何学Pythonompany, atm I'm implementing a REST API that shoves XML around. I saw that there is an XMLApiHelper that offers the createTag method that encapsulates the responses in a root element.
So I did this
object RestAPI extends RestHelper with XMLApiHelper {
serve {
…
}
…
def createTag(in: NodeSeq): Elem = <root>{in}</root>
}
This does not seem to work. Am I missing something?
Regards, raichoo
RestHelper
and XMLApiHelper
are not meant to work together. They are meant to solve two different kinds of problems.
XMLApiHelper
defines an implicit conversion between the XML Node Scala types and the LiftResponse class. RestHelper
defines a mechanism which will return either XML
or JSON
to the client, depending on what they asked for. RestHelper
ties into the dispatch process at a lower level than XMLApiHelper
, so the implicit on XMLApiHelper
never actually gets called.
If you only want to return XML
to an HTTP method, use XMLApiHelper
. If you want the flexibility to return XML
or JSON
depending on how the HTTP method is called, then use the RestHelper
.
精彩评论