Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: finish rest constructors


According to Groovy Builders, constructors can be nested to each other. In that case, GroovyRestlet will automatically set up Restlet-specific relationship between parent and child instances. But user can disable this feature by setting autoAttach attribute as false.

In Restlet, the Router.attach method returns a Route instance. In order to do some special process on the Route instance, an attribute postAttach which refers to a Groovy closure is provided. For example:

Code Block

    restlet(uri:"/users/{user}", postAttach:{route->
       //do some post attaching process here

Another important attribute is uri which indicates a URI Template using by Restlet Router.


The generic constructor for all components of type of Restlet. You can use ofClass attribute to indicate restlet to create an instance of a subtype. When doing that, using attribute consArgs to provide arguments array of corresponding constructor. For example:


  • protocol: the client protocol
  • protocols: a list of client protocols


A shortcut to create a Restlet Component. If no VirtualHost is specified, direct children of component constructor will be attached to Component's default VirtualHost. For example,

Code Block


Which is equivalent to Java code:

Code Block

Component component = new Component();
component.getDefaultHost().attach("", new Application());


A shortcut to create a Restlet Application. The direct child of application constructor, without attribute autoAttach as false, will be set as the root of the application instance. If more direct nested constructors are defined, only the last one will be selected.


A shortcut to create a Restlet Router. A router constructor can have one or more nested children. Each child will be attached to the router by calling Router.attach method.


A shortcut to create a Restlet Filter.

  • before: a closure to be called when Filter.beforeHandle is called;
  • after: a closure to be called when Filter.afterHandle is called;
  • handle: a closure to be called when Filter.doHandle is called;


A shortcut to create a Restlet Redirector.


A shortcut to create a Restlet Guard.

  • scheme: the challenge scheme, will use ChanllengeScheme.valueOf("None") if no scheme is provided;
  • realm: the authentication realm


A shortcut to create a Restlet Directory. A directory constructor can not nest child.

  • root: the root uri of the Directory


A shortcut to create a Restlet Resource. A resource constructor can not nest child; and it can be nested in filter and router.


resource constructor provides a set of closure attributes for easily handling RESTful calls.

  • store: for handling HTTP PUT method
  • remove: for handling HTTP DELETE method
  • accept: for handling HTTP POST method
  • represent: for handling HTTP GET method
  • head: for handling HTTP HEAD method
  • options: for handling HTTP OPTIONS method

These closures are only effected when no ofClass and ofBean attribute is specified.