Over a million developers have joined DZone.

Grape Mounted behind Goliath

See Gartner’s latest research on the application performance monitoring landscape and how APM suites are becoming more and more critical to the business, brought to you in partnership with AppDynamics.

Got a chance to play with Goliath for a bit. You don’t need to do much work to mount Grape behind it. Grape figures out content-negotiation and formatting for you, so just stream the response through Goliath.

    module Acme
      class Ping < Grape::API
        format :json
        get '/ping' do
          { ping: "pong" }
        end
      end
     
      class App < Goliath::API
        use Goliath::Rack::Params
        use Goliath::Rack::Render
     
        def response(env)
          Acme::API.call(env)
        end
      end
    end

Tests for something like this are a little bit tricky, because Goliath is fully asynchronous.

    describe Acme::API do
      it "ping" do
        with_api Acme::App do
          get_request(path: "/api/ping") do |async|
            async.response.should == { ping: "pong" }.to_json
          end
        end
      end
    end

Working code in https://github.com/dblock/grape-on-goliath.

There’s also a very complete demo with asynchronous IO and PostgreSQL here. Haven’t tried it, but looks very promising.



The Performance Zone is brought to you in partnership with AppDynamics.  See Gartner’s latest research on the application performance monitoring landscape and how APM suites are becoming more and more critical to the business.

Topics:

Published at DZone with permission of Daniel Doubrovkine. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}