Description
The REST plugin enables the usage of HTTPBuilder on a Griffon application.
Installation
The current version of griffon-rest-plugin is 0.7.1
To install just issue the following command
Usage
The plugin will inject the following dynamic methods:
- withHttp(Map params, Closure stmts) - executes
stmtsusing aHTTPBuilder - withAsyncHttp(Map params, Closure stmts) - executes
stmtsusing anAsyncHTTPBuilder - withRest(Map params, Closure stmts) - executes
stmtsusing aRESTClient
Where params may contain
Property |
Type |
Required |
Notes |
|---|---|---|---|
uri |
String |
|
|
contentType |
String |
|
|
id |
String |
|
|
proxy |
Map |
|
proxy settings [scheme: 'http'|'https', port: 80, host: ""] |
These methods are also accessible to any component through the singleton griffon.plugins.rest.RestConnector. You can inject these methods to non-artifacts via metaclasses. Simply grab hold of a particular metaclass and call RestConnector.enhance(metaClassInstance).
Examples
Taken from HttpBuilder's Simplified GET Request
| Note Notice that you can call HTTPBuilder's methods inside |
All dynamic methods will create a new http client when invoked unless you define an id: attribute. When this attribute is supplied the client will be stored as a property on the instance's metaClass. You will be able to access it via regular property access or using the id: again.
Here's an example of a non-griffon artifact making a REST call to Flickr
Finally, it's possible to call any of RestConnector's method from Java passing a CallableWithArgs instance instead of a Closure, like this
Configuration
Dynamic method injection
Dynamic methods will be added to controllers by default. You can change this setting by adding a configuration flag in Config.groovy
Proxy settings
You can apply proxy settings by calling setProxy(String host, int port, String scheme) on the client/builders at any time. You can also take advantage of the proxy: shortcut
This shortcut has the following defaults
port:= 80scheme:= http
Meaning most of the times you'd only need to define a value for host:
History
Version |
Date |
Notes |
|---|---|---|
0.7.1 |
10-21-11 |
Release sync with Griffon 0.9.4 |
0.7 |
09-15-11 |
Added RestConnector |
0.6 |
12-21-10 |
Release sync with Griffon 0.9.2. Upgraded to HttpBuilder 0.5.1 |
0.5.1 |
11-08-10 |
Fix a metaclass problem when injecting dynamic methods |
0.5 |
10-27-10 |
Release sync with Griffon 0.9.1 |
0.4 |
07-22-10 |
Release sync with Griffon 0.9 |
0.3 |
03-01-10 |
Upgraded to Griffon 0.3 |
0.2 |
10-26-09 |
Updated dependencies to HTTPBuilder-0.5-RC2, removed xml-apis |
0.1 |
10-13-09 |
Initial release |