Groovy DSL for constructing Restlet application |
GroovyRestlet is distributed as a single jar.
GroovyRestlet 0.3-SNAPSHOT, donwload here
Changes
directory constructor now only accept root attribute as valid URI.At current moment, GroovyRestlet depends following:
Drop GroovyRestlet and all dependencies in your Java classpath.
First, create an instance of GroovyRestlet first.
GroovyRestlet gr = new GroovyRestlet() |
|
If you want Spring support, provide an instance of |
GroovyRestlet gr = new GroovyRestlet(appCtx); |
Then, prepare your Restlet building script using simple GroovyRestlet DSL syntax.
Calling GroovyRestlet.build(URI) then done.
Check GroovyRestlet User Guide for detail user information.
Here is one GroovyRestlet DSL example, inspired from Restlet tutorial 11.
builder.component{
current.servers.add(protocol.HTTP, 8182)
application(uri:""){
router{
def guard = guard(uri:"/docs", scheme:challengeScheme.HTTP_BASIC,
realm:"Restlet Tutorials")
guard.secrets.put("scott", "tiger".toCharArray())
guard.next = directory(root:"", autoAttach:false)
restlet(uri:"/users/{user}", handle:{req,resp->
resp.setEntity("Account of user \"${req.attributes.get('user')}\"",
mediaType.TEXT_PLAIN)
})
restlet(uri:"/users/{user}/orders", handle:{req, resp->
resp.setEntity("Orders or user \"${req.attributes.get('user')}\"",
mediaType.TEXT_PLAIN)
})
restlet(uri:"/users/{user}/orders/{order}", handle:{req, resp->
def attrs = req.attributes
def message = "Order \"${attrs.get('order')}\" for User \"${attrs.get('user')}\""
resp.setEntity(message, mediaType.TEXT_PLAIN)
})
}
}
}.start()
|
For more examples:
http://svn.codehaus.org/groovy-contrib/groovyrestlet/trunk
GroovyRestlet uses Maven 2 as its building tool.
Feel free to contribute.
http://groovy.codehaus.org/Mailing+Lists
http://code.google.com/p/groovy-restlet/issues/