Giter VIP home page Giter VIP logo

rack-client's Introduction

What’s this?

Rack::Client is an HTTP client that aims to be a good Rack
citizen.

Install

To install the latest release as a gem:

sudo gem install rack-client

Then in Ruby:
require “rubygems”; require “rack/client” # and you’re off!

Rack responses

Rack::Client can be used to make HTTP requests to any type of server, not
just ones using Rack. However, when a request is made then a proper
Rack response (specifically a Rack::MockResponse) object is returned.
For Rubyists, this means you don’t need to learn yet another interface
and can just stick with Rack both on the server, test, and client side of
things.

response = Rack::Client.get("http://some-website.com/blah.txt")
response.code #=> 200
response.body #=> "some body"

Middleware

Rack::Client is actually a subclass of Rack::Builder. This means that
Rack::Client objects yield actual Rack apps. More importantly, this
means you can reuse existing Rack middleware on the client side too
(but also feel free to make new middleware that only makes sense on
the client side under the Rack::Client namespace). Note that by default
Rack::Client will “run” Rack::Client::HTTP as an endpoint, but this
will not be performed if you specify your own “run” endpoint.

client = Rack::Client.new { use Rack::ETag }
response = client.get("http://localhost:9292/no-etag")

Rack::Test compatibility

Rack::Client reuses a lot of Rack::Test to provide users with a
familiar interface. What’s even cooler is that you can use a
Rack::Client object as your “app” in Rack::Test. This means that you
can test-drive an application with Rack::Test, then when ready
actually run your Rack app, switch your Rack::Test “app” to a
Rack::Client, and get free full-blown integration testing! Note that
the integration-tested server does not need to be all-Rack, so you can
develop quickly with middleware like Rack::Cache but then remove it
and integration test with a dedicated cache server like Varnish.

# NOTE: For a complete example, look in the "demo" directory
describe Demo, "/store resource" do
  include Rack::Test::Methods
  def app
    # replace this with Rack::Client.new
    # for integration testing
    Demo::App.new
  end
  # ... etc
end

Contributors

halorgium, larrytheliquid, benburkert

rack-client's People

Contributors

benburkert avatar ultraninja avatar halorgium avatar larrytheliquid avatar danp avatar benschwarz avatar atmos avatar igrigorik avatar technicalpickles avatar mattetti avatar

Stargazers

JD Huntington avatar

Watchers

JD Huntington avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.