Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 71 lines (56 sloc) 2.33 kb
02cd4c4 Added README, LICENSE, and a demo app
Larry Diehl authored
1 h1. What's this?
2
3 Rack::Client is an HTTP client that aims to be a good Rack
4 citizen.
5
fe8ebbc Added install instructions to readme
Larry Diehl authored
6 h1. Install
7
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>
12
02cd4c4 Added README, LICENSE, and a demo app
Larry Diehl authored
13 h2. Rack responses
14
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
authored
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.
21
22 <pre>
23 response = Rack::Client.get("http://some-website.com/blah.txt")
24 response.code #=> 200
25 response.body #=> "some body"
26 </pre>
27
28 h2. Middleware
29
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.
37
38 <pre>
39 client = Rack::Client.new { use Rack::ETag }
40 response = client.get("http://localhost:9292/no-etag")
41 </pre>
42
43 h2. Rack::Test compatibility
44
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.
54
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 Rack::Client.new
61 # for integration testing
62 Demo::App.new
63 end
64 # ... etc
65 end
66 </pre>
67
68 h1. Contributors
69
42d5737 Credit
Larry Diehl authored
70 halorgium, larrytheliquid, benburkert
Something went wrong with that request. Please try again.