Imagine I have this scenario in my Controller:
def nr_1 = params.first_nr
def nr_2 = params.second_nr
def result
def erro = 'no'
if(nr_1.isInteger() && nr_2.isInteger())
result = nr_1.toInteger() * nr_2.toInteger()
else
erro = 'yes'
if(erro.equals('yes'))
[sms : 'Please introduce only 2 numbers!']
else
[sms: 'The result of the multiplication of ' + nr_1 + ' with ' + nr_2 + ' is ' + result]
This is returned to my gsp view and it is successfully done. Now I want to transform this into a REST access Web Service. The way im seeing this, I’ll have to manually create the tags like this:
<firstNumber>nr_1</firstNumber>
<secondNumber>nr_1</secondNumber>
<result>result</result>
and then return to the rest request. How can I accomplish this (By providing both HTML and XML response, and for XML, parse only the last XML tags).
You can create an object that represent your request and put the content of your request in it.
It will enable you to us
render as XMLto generate your XML in your action:Don’t forget to
import grails.converters.*at the beginning of your controller.