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()
Written by Baruch Sadogursky
Related protips
2 Responses
FYI, Not needed in http-builder 0.7
over 1 year ago
·
Yup.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Groovy
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#