I have this controller:
def list = {
withFormat {
xml { render Customer.list() as XML }
html {
params.max = Math.min(params.max ? params.int('max') : 10, 100)
[customerInstanceList: Customer.list(params), customerInstanceTotal: Customer.count()]
}
}
}
Which basically shows me all customers in my webpage, but it is also aimed to list as xml for a rest response. I’m using WizTools Rest Client 2.33 to call list method via rest. What is happening here is, if I call the controller via browser, everything works fine and all customers are listed as html in the page. If I call it via rest, the response I get is the same html page code rendered. In the code above, I tried to take out the html part, and that way the rest response is what I expect (xml). So, I think something might be missing, because the controller is not being able to recognise a rest request. Any help would be appreciated.
The way withFormat works is by looking at, for lack of a better term, the action extension. If you want xml to return instead of html, you’re URL would need be something like:
http://localhost/app/customer/list.xml