Over a million developers have joined DZone.

HTTPBuilder 0.3.1 released


HTTPBuilder is a Groovy wrapper around Apache's HttpClient, with a response handling model similar to Prototype.js' Ajax.Request.  It also supports automatic response parsing and request building based on content-type, and convenience features for common authentication and content-encoding schemes.

 HTTPBuilder can be used for simple ad-hoc HTTP queries, or as a REST client like so:

// Use Google's JSON API to perform a search query:
builder.request( 'http://ajax.googleapis.com', GET, JSON ) {
url.path = '/ajax/services/search/web'
url.query = [ v:'1.0', q: 'Calvin and Hobbes' ]
headers.'User-Agent' = "Mozilla/5.0"

// the response is automatically parsed into a JSON object:
response.success = { resp, json ->
assert json.size() == 3

println "Query response: "
json.responseData.results.each {
// print each search result and the URL:
println " ${it.titleNoFormatting} : ${it.visibleUrl}"

 See more examples here.

Built-in content-types (supported for parsing and POSTing data) include:

  • XML and HTML (using XmlSlurper and NekoHTML)
  • JSON (thanks to json-lib)
  • form-urlencoded (transformed to/from a Map)
  • text (as a Reader and Writer, automatically using the correct charset)
  • binary (using InputStream/ OutputStream)

Latest binaries and source packages are available on Maven and the site's download page.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}