On Tue, May 5, 2009 at 2:16 PM, Tim Carey-Smith <g@spork.in> wrote:

Hey there,

I've been dealing with the painful API that is Net::HTTP and RestClient.

It seems to me that it would make sense for there to be a client lib which accepted a Rack environment and made a real HTTP request on the wire.
This would return the Rack response: [status, headers, body] and allow people to build tools which worked against a real web-service as well as a Rack app.

I've got an implementation for doing this using Mechanize as the backend, but it feels to weighty.
As I would see it, the library would allow the following:

res = Rack::MockRequest.new(RackClient::HTTP.new).get("/foo", "HTTP_HOST" => "example.org")

Which would result in 'res' containing the data at http://example.org/foo

Does this sound like a good idea? It means we can leverage the power of middleware on the client-side too.

app = Rack::Builder.app do
 # For http auth
 use RackClient::Auth::Basic, "username", "password"
 # For json serialization
 use RackClient::JSON
 run RackClient::HTTP
end

This could probably be wrapped in a nicer API, but I think that shows the general idea.

Please tell me I'm missing something insanely stupid and this has been thought of and rejected before.
(Or not...)

Ciao,
Tim

I really like this idea.  I can think of a couple of things I'd like to use it for already.

Cheers
Daniel