REST Gradle Plugin Update

It’s been a while since I updated the REST Gradle Plugin but necessity is the mother of invention (but what the fuck have I ever invented?) so here we go!

Up until now whatever type of REST request you made using the plugin, the output would have been printed to the build log.
If you were lucky and nosy you might’ve discovered that you can access the internal response object, but no more are you deprived of information!

Starting from version 0.4.0 you can now declare a closure to handle successful responses, yay!

Declaring A Response Handler

For example if we would like to download a binary file and save it to the disk, then we would declare:

task download(type: {
    uri = ''
    responseHandler = { InputStream is ->
        new File('/home/user/file.bin').withOutputStream { Outputstream os ->
            os << is

Type handling

If the plugin detects that the given responseHandler closure accepts a parameter of type InputStream or String, it will pass the response body of the respective type. Otherwise, the plugin will fall back to HTTPBuilder’s response and hand the closure the data object that was created by the client.


For example if we query a resource that returns a JSON response, we state that the expected content type is JSON, and HTTPBuilder already parses the response and slurps it:

task download(type: {
    uri = ''
    contentType =
    responseHandler = {
        assert it.results.size() == 50


4 thoughts on “REST Gradle Plugin Update

  1. I try to use this plugin both in Java and Android projects.
    But getting an error:
    Error:(4, 0) Cause: org/_10ne/gradle/rest/RestPlugin : Unsupported major.minor version 52.0

    gradle -v
    Gradle 2.5
    Build time: 2015-07-08 07:38:37 UTC
    Build number: none
    Revision: 093765bccd3ee722ed5310583e5ed140688a8c2b
    Groovy: 2.3.10
    Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
    JVM: 1.7.0_79 (Oracle Corporation 24.79-b02)
    OS: Mac OS X 10.10.5 x86_64

    java -version
    java version “1.7.0_79”
    Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
    Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

    I am wondering, what does it means ?!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s