Question

I'm doing a project to test Scala and Lift at my company, 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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top