I am trying to create REST web service with grails 5.1.7. Have checked the documentation for Grails REST on its official site and followed the steps to create services.
Currently got a situation where a webflow kind of feature needs to be performed, so to deal with we will be creating a single action which will handle session objects (which are to be transferred between steps of the webflow). Now the matter is how the GSON view will be resolved for each steps, as there will be single action will be serving all the steps of the webflow (there are 6 steps of the webflow). With HTML/GSP response of grails we can pass on "view" file to be used for any action. But for REST response, how to specify which GSON view should respond the result of the step?
I tried respond (just to experiment) (view: "handleDefineStep", model: modelMap)
, but it did not work. The document says that view and model should be used for HTML response so it is clear that it would not work.
One thing I would like to note that there is no domain classes in our project so domain rendering will not be there. Data are transferred using command objects created under src/main/groovy
.
A sample code snippet for webflow is like:
def initializeFlow() {
// ... initialize some objects and store them to session to be used at other actions
def currentStep = params.step
switch(currentStep) {
case "step1":
handleStep1() // This action has its own GSON response to respond with
break;
case "step2":
handleStep2() // This action also has its own GSON response to respond with and likewise
break;
// ...
}
// ...
}
Update handleStep1 method:
def handleStep1() {
// ...
respond (model, view: "editPage/handleDefineStep")
}