项目详情
由分享
HelloGitHub 评分
0 人评分
开源•MIT
认领
讨论
收藏
分享
5.2k
星数
否
中文
Ruby
主语言
否
活跃
91
贡献者
142
Issues
是
组织
无
最新版本
931
Forks
MIT
协议
更多
一个 Ruby 的 HTTP 客户端库。已经有累计 10 万人在使用,该库使用方便、API 设计优雅、支持常用的 HTTP 方法、文件下载、设置代理等。每个方法基本都有示例代码:
```ruby
require 'rest_client'
RestClient.get 'http://example.com/resource'
RestClient.get 'http://example.com/resource', {:params => {:id => 50, 'foo' => 'bar'}}
RestClient.get 'https://user:password@example.com/private/resource', {:accept => :json}
RestClient.post 'http://example.com/resource', :param1 => 'one', :nested => { :param2 => 'two' }
RestClient.post "http://example.com/resource", { 'x' => 1 }.to_json, :content_type => :json, :accept => :json
RestClient.delete 'http://example.com/resource'
response = RestClient.get 'http://example.com/resource'
response.code
➔ 200
response.cookies
➔ {"Foo"=>"BAR", "QUUX"=>"QUUUUX"}
response.headers
➔ {:content_type=>"text/html; charset=utf-8", :cache_control=>"private" ...
response.to_str
➔ \n<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n \"http://www.w3.org/TR/html4/strict.dtd\">\n\n<html ....
RestClient.post( url,
{
:transfer => {
:path => '/foo/bar',
:owner => 'that_guy',
:group => 'those_guys'
},
:upload => {
:file => File.new(path, 'rb')
}
})
```
评论
评分:
暂无精选评论