HTTPBuilder Overview

HTTP Builder - Home

HTTPBuilder Overview

HTTPBuilder is the easiest way to manipulate HTTP-based resources from the JVM.

In a nutshell, HTTPBuilder is a wrapper for Apache's HttpClient, with some (actually, a lot of) Groovy syntactical sugar thrown on top. The request/response model is also inspired by Prototype.js' Ajax.Request.

In short, HTTPBuilder allows you to make HTTP requests like this:

def http = new HTTPBuilder( 'http://ajax.googleapis.com' )
 
// perform a GET request, expecting JSON response data
http.request( GET, JSON ) {
   uri.path = '/ajax/services/search/web'
   uri.query = [ v: '1.0' , q: 'Calvin and Hobbes' ]
 
   headers. 'User-Agent' = 'Mozilla/5.0 Ubuntu/8.10 Firefox/3.0.4'
 
   // response handler for a success response code:
   response.success = { resp, json ->
     println resp.status
 
     // parse the JSON response object:
     json.responseData.results. each {
       println "  ${it.titleNoFormatting} : ${it.visibleUrl}"
     }
   }
 
   // handler for any failure status code:
   response.failure = { resp ->
     println "Unexpected error: ${resp.status} : ${resp.statusLine.reasonPhrase}"
   }
}

But it actually goes much further to handle common tasks such as building and parsing common content-types, handling common content-encodings, and built-in support for common authentication mechanisms. It works equally as well for simple REST-based requests, or ad-hoc web downloads.

Features

Components

HTTPBuilder is the main API class which is used to make requests and parse responses. AsyncHTTPBuilder is a subclass of the base HTTPBuilder which transparently delegates all requests to a thread pool for execution. RESTClient extends HTTPBuilder to eliminate the closure definition, to make REST operations particularly easy. Finally, HttpURLClient provides most of HTTPBuilder's intelligent handling in a package that can be used from Google App Engine.

URIBuilder provides a fluent interface for manipulating complex URLs. It is also used internally by HTTPBuilder to handle path and query string modification.

See the JavaDoc for full documentation.

Requirements

  • At least Java 1.5. This is because HttpClient 4 requires Java 5.
  • Groovy 1.5 or later, although it should work with earlier versions
  • JAR dependencies can be found in the packaged distributions linked from the downlo
posted on 2012-06-28 15:28  lexus 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lexus/archive/2012/06/28/2567691.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值