REST client plugin that uses Spring's RestTemplate
Switch branches/tags
Nothing to show
Pull request Compare This branch is 52 commits behind grails-plugins:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Rest Client Builder Grails Plugin


Edit BuildConfig.groovy and add the following dependency:

compile ":rest-client-builder:1.0"

Basic Usage

Main entry point is the class. Construct and use one of the REST "verbs".

A GET request:

 def resp = rest.get("")

The response is a Spring ResponseEntity.

There are convenience methods for obtaining JSON:

  resp.json instanceof JSONObject == 'acegi'

And XML:

  resp.xml instanceof GPathResult == 'acegi'

POST and PUT requests

POST and PUT requests can be issued with the post and put methods respectively:

        def resp = rest.put(""){
            auth System.getProperty("artifactory.user"), System.getProperty("artifactory.pass")
            contentType "application/"
            json {
                name = "test-group"
                description = "A temporary test group"

In the example above the auth method performs HTTP basic auth, the contentType method sets the content type, and the json method constructs a JSON body.

Multipart Requests

Multipart requests are possible by setting properties of the request body to File, URL, byte[] or InputStream instances:

    def resp = {
        contentType "multipart/form-data"
        zip = new File(pluginPackage)
        pom = new File(pomFile)
        xml = new File(pluginXmlFile)

Connection/Proxy Configuration

Connection and proxy configuration can be specified in the constructor to RestBuilder:

def rest = new RestBuilder(connectTimeout:1000, readTimeout:20000, proxy:['localhost':8888])

The proxy setting can either be map containing the key for the host name and a value for the port or an instance of