igrigorik / em-http-request
- Source
- Commits
- Network (21)
- Issues (5)
- Downloads (0)
- Wiki (1)
- Graphs
-
Tree:
e083258
commit e083258429a4a9ddc8fb0f018c6f0bdedcff3e73
tree 6fc3da4aedd507470c509fb9c79e912d5eba7877
parent f2d6914b16da4d0344bba2fb75bb3fff76dc39b5
tree 6fc3da4aedd507470c509fb9c79e912d5eba7877
parent f2d6914b16da4d0344bba2fb75bb3fff76dc39b5
| name | age | message | |
|---|---|---|---|
| |
.autotest | Fri Aug 22 10:56:57 -0700 2008 | |
| |
.gitignore | Sun Feb 01 10:47:43 -0800 2009 | |
| |
LICENSE | Fri Aug 22 10:56:57 -0700 2008 | |
| |
README.rdoc | ||
| |
Rakefile | ||
| |
em-http-request.gemspec | ||
| |
examples/ | ||
| |
ext/ | ||
| |
lib/ | ||
| |
test/ |
README.rdoc
EM-HTTP-Client
EventMachine based HTTP Request interface. Supports streaming response processing, uses Ragel HTTP parser.
- Simple interface for single & parallel requests via deferred callbacks
- Automatic gzip & deflate decoding
- Basic-Auth support
- Custom timeouts
Simple client example
EventMachine.run {
http = EventMachine::HttpRequest.new('http://127.0.0.1/').get :query => {'keyname' => 'value'}, :timeout => 10
http.callback {
p http.response_header.status
p http.response_header
p http.response
EventMachine.stop
}
}
Multi request example
EventMachine.run {
multi = EventMachine::MultiRequest.new
# add multiple requests to the multi-handler
multi.add(EventMachine::HttpRequest.new('http://www.google.com/').get)
multi.add(EventMachine::HttpRequest.new('http://www.yahoo.com/').get)
multi.callback {
p multi.responses[:succeeded]
p multi.responses[:failed]
EventMachine.stop
}
}
Basic-Auth example
EventMachine.run {
http = EventMachine::HttpRequest.new('http://www.website.com/').get :head => {'authorization' => ['user', 'pass']}
http.errback { failed }
http.callback {
p http.response_header
EventMachine.stop
}
}
POST example
EventMachine.run {
http1 = EventMachine::HttpRequest.new('http://www.website.com/').post :body => {"key1" => 1, "key2" => [2,3]}
http2 = EventMachine::HttpRequest.new('http://www.website.com/').post :body => "some data"
# ...
}
Streaming body processing
EventMachine.run {
body = ''
on_body = lambda { |chunk| body += chunk }
http = EventMachine::HttpRequest.new('http://www.website.com/').get :on_response => on_body
# ...
}

