Versions Compared

Key

  • 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

builder.router{
    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.

restlet

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

component

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

builder.component{
    application(uri:"")
}

Which is equivalent to Java code:

Code Block

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

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.

router

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.

filter

A shortcut to create a Restlet Filter.

Attributes
  • 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;

redirector

A shortcut to create a Restlet Redirector.

guard

A shortcut to create a Restlet Guard.

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

directory

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

Attributes:
  • root: the root uri of the Directory

resource

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

Attributes

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.