Skip to content


Subversion checkout URL

You can clone with
Download ZIP
100644 71 lines (56 sloc) 2.33 kb
02cd4c4 Added README, LICENSE, and a demo app
Larry Diehl authored
1 h1. What's this?
3 Rack::Client is an HTTP client that aims to be a good Rack
4 citizen.
fe8ebbc Added install instructions to readme
Larry Diehl authored
6 h1. Install
8 To install the latest release as a gem:
9 <pre>sudo gem install rack-client</pre>
10 Then in Ruby:
11 <pre>require "rubygems"; require "rack/client" # and you're off!</pre>
02cd4c4 Added README, LICENSE, and a demo app
Larry Diehl authored
13 h2. Rack responses
15 Rack::Client can be used to make HTTP requests to any type of server, not
16 just ones using Rack. However, when a request is made then a proper
036c4e9 @halorgium Update the code to use the bundler and make it clean
17 Rack response (specifically a Rack::MockResponse) object is returned.
18 For Rubyists, this means you don't need to learn yet another interface
02cd4c4 Added README, LICENSE, and a demo app
Larry Diehl authored
19 and can just stick with Rack both on the server, test, and client side of
20 things.
22 <pre>
23 response = Rack::Client.get("")
24 response.code #=> 200
25 response.body #=> "some body"
26 </pre>
28 h2. Middleware
30 Rack::Client is actually a subclass of Rack::Builder. This means that
31 Rack::Client objects yield actual Rack apps. More importantly, this
32 means you can reuse existing Rack middleware on the client side too
33 (but also feel free to make new middleware that only makes sense on
34 the client side under the Rack::Client namespace). Note that by default
35 Rack::Client will "run" Rack::Client::HTTP as an endpoint, but this
36 will not be performed if you specify your own "run" endpoint.
38 <pre>
39 client = { use Rack::ETag }
40 response = client.get("http://localhost:9292/no-etag")
41 </pre>
43 h2. Rack::Test compatibility
45 Rack::Client reuses a lot of Rack::Test to provide users with a
46 familiar interface. What's even cooler is that you can use a
47 Rack::Client object as your "app" in Rack::Test. This means that you
48 can test-drive an application with Rack::Test, then when ready
49 actually run your Rack app, switch your Rack::Test "app" to a
50 Rack::Client, and get free full-blown integration testing! Note that
51 the integration-tested server does not need to be all-Rack, so you can
52 develop quickly with middleware like Rack::Cache but then remove it
53 and integration test with a dedicated cache server like Varnish.
55 <pre>
56 # NOTE: For a complete example, look in the "demo" directory
57 describe Demo, "/store resource" do
58 include Rack::Test::Methods
59 def app
60 # replace this with
61 # for integration testing
63 end
64 # ... etc
65 end
66 </pre>
68 h1. Contributors
42d5737 Credit
Larry Diehl authored
70 halorgium, larrytheliquid, benburkert
Something went wrong with that request. Please try again.