Protocol bound call in Grails

Posted By : Ashish Sharma | 05-Feb-2014

Protocol Bound Call in Grails

There are two ways in which we can bind our actions to a particular protocol

  • First one is to bind the actions to protocol in the declaration, in the controller

    			class UserController {
    			
    				static allowedMethods = [createUser: "POST",
    					editUser: "PUT",
    					deleteUser: "DELETE",
    					getUser: "GET"]
    					
    				def createUser(){
    					...
    				}
    				....
    			}
    		
  • Second one is to bind the actions to protocol in the UrlMapping

    			class UrlMappings {
    				static mappings = {
    					.....
    					"/user/$id(.${format})"(controller:"user", parseRequest:true){
    						action = [DELETE:"deleteUser", GET:"getUser", PUT:"editUser"]
    					}
    					"/user(.${format})"(controller:"user", parseRequest:true){
    						action = [POST: "createUser"]
    					}
    					...
    				}
    			}
    		

About Author

Author Image
Ashish Sharma

Ashish is a bright Groovy and Grails developer and have worked on development of various SaaS applications using Grails technologies. Ashish likes PC games and works out at Gym in his free time.

Request for Proposal

Name is required

Comment is required

Sending message..