9hnihq
Last Updated: February 25, 2016
·
1.351K
· jbaruch
3d73332968c0bf62e1ece7299deb8b37

Running HTTP PATCH requests with Groovy HttpBuilder

As of version 0.6 HttpBuilder does not support HTTP PATCH methods (Enum limitations strike again). Here's how you do it:

import groovyx.net.http.*
import org.apache.http.client.methods.HttpPatch

@Grab(group = 'org.codehaus.groovy.modules.http-builder', module = 'http-builder', version = '0.6')
@Grab(group = 'org.apache.httpcomponents', module = 'httpcomponents-client', version = '4.2')
def runPatch() {
    //serverinfo.groovy just returns the request method
    //Method.DELETE is switched, and won't be used (can't use null, NPE)
    new HTTPBuilder('http://localhost:9090/serverinfo.groovy').request(Method.DELETE) {
        delegate.request = new HttpPatch()
        response.success = { resp, body ->
            assert resp.status == 200
            assert body == 'PATCH'
        }
    }
}

runPatch()
Say Thanks
Respond

2 Responses
Add your response

13849

FYI, Not needed in http-builder 0.7

over 1 year ago ·
13866
3d73332968c0bf62e1ece7299deb8b37

Yup.

over 1 year ago ·