aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2015-11-03 16:27:27 +0900
committerKazuki Yamaguchi <k@rhe.jp>2015-11-03 16:27:27 +0900
commit3fb060945fb27a17024df8795d0712b3d3d714f2 (patch)
treef77da08bf22e2ae9e2e1e1e9abcd1d3e5194033f /README.md
parentc3dacc27e2efaa9ded721e71f35824fcb4e6dfc3 (diff)
downloadplum-3fb060945fb27a17024df8795d0712b3d3d714f2.tar.gz
update README
Diffstat (limited to 'README.md')
-rw-r--r--README.md58
1 files changed, 52 insertions, 6 deletions
diff --git a/README.md b/README.md
index a138b44..4c906cb 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
# Plum [![Build Status](https://travis-ci.org/rhenium/plum.png?branch=master)](https://travis-ci.org/rhenium/plum) [![Code Climate](https://codeclimate.com/github/rhenium/plum/badges/gpa.svg)](https://codeclimate.com/github/rhenium/plum) [![Test Coverage](https://codeclimate.com/github/rhenium/plum/badges/coverage.svg)](https://codeclimate.com/github/rhenium/plum/coverage)
-A minimal pure Ruby implementation of HTTP/2 library / server.
+A pure Ruby HTTP/2 implementation.
## Requirements
* Ruby
@@ -7,14 +7,55 @@ A minimal pure Ruby implementation of HTTP/2 library / server.
* or latest Ruby 2.3.0-dev
* OpenSSL 1.0.2 or newer (HTTP/2 requires ALPN)
* Optional:
- * [http-parser.rb gem](https://rubygems.org/gems/http_parser.rb) (HTTP/1.1 parser; if you use "http" URI scheme)
+ * [http_parser.rb gem](https://rubygems.org/gems/http_parser.rb) (HTTP/1.1 parser; if you use "http" URI scheme)
* [rack gem](https://rubygems.org/gems/rack) if you use Plum as Rack server.
## Usage
-### As a library
-* See documentation: http://www.rubydoc.info/gems/plum
-* See examples in `examples/`
-* [rhenium/plum-server](https://github.com/rhenium/plum-server) - A static-file server for https://rhe.jp and http://rhe.jp.
+### As a HTTP/2 client library
+##### Sequential request
+```ruby
+client = Plum::Client.start("http2.rhe.jp", 443)
+res1 = client.get("/")
+puts res1.body # => "..."
+res2 = client.post("/post", "data")
+puts res2.body # => "..."
+
+client.close
+```
+
+##### Parallel request
+```ruby
+client = Plum::Client.start("http2.rhe.jp", 443)
+res1 = client.get_async("/")
+res2 = client.post_async("/post", "data")
+client.wait # wait for response(s)
+client.close
+p res1.status # => 200
+```
+or
+```ruby
+res1 = res2 = nil
+Plum::Client.start("http2.rhe.jp", 443) { |client|
+ res1 = client.get_async("/")
+ res2 = client.post_async("/post", "data")
+} # wait for response(s) and close
+
+p res1.status # => 200
+```
+
+##### Download large file
+```ruby
+Plum::Client.start("http2.rhe.jp", 443) { |client|
+ client.get_async("/large") do |res|
+ p res.status # => 200
+ File.open("/tmp/large.file", "wb") { |file|
+ res.each_body do |chunk|
+ file << chunk
+ end
+ }
+ end
+}
+```
### As a Rack-compatible server
@@ -41,6 +82,11 @@ You can run it:
By default, Plum generates a dummy server certificate if `--cert` and `--key` options are not specified.
+### As a library
+* See documentation: http://www.rubydoc.info/gems/plum
+* See examples in `examples/`
+* [rhenium/plum-server](https://github.com/rhenium/plum-server) - A static-file server for https://rhe.jp and http://rhe.jp.
+
## TODO
* **Better API**