Last Updated: February 25, 2016
·
4.214K
· jbaruch

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()

2 Responses
Add your response

FYI, Not needed in http-builder 0.7

over 1 year ago ·

Yup.

over 1 year ago ·