Skip to content

Instantly share code, notes, and snippets.

Created July 31, 2013 08:25
Show Gist options
  • Save anonymous/6120313 to your computer and use it in GitHub Desktop.
Save anonymous/6120313 to your computer and use it in GitHub Desktop.
PUT method testing using HttpBuilder
/**
* HttpBuilder Testing
*/
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.2' )
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
def http = new HTTPBuilder( 'http://localhost:8080' )
http.request( PUT, JSON ) {
uri.path = '/test1/rest/testPut'
uri.query = [ v:'1.0', q: 'Calvin and Hobbes' ]
body = [ a:1, b:2, c:3 ]
headers.'User-Agent' = 'Mozilla/5.0 Ubuntu/8.10 Firefox/3.0.4'
response.success = { resp, json ->
println resp.statusLine
println json.result
}
response.failure = { resp ->
println "Unexpected error: ${resp.statusLine.statusCode} : ${resp.statusLine.reasonPhrase}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment