Over a million developers have joined DZone.
Platinum Partner

Grape Mounted behind Goliath

The Performance Zone is brought to you in partnership with New Relic. Quickly learn how to use Docker and containers in general to create packaged images for easy management, testing, and deployment of software.

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" }
      class App < Goliath::API
        use Goliath::Rack::Params
        use Goliath::Rack::Render
        def response(env)

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

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 New Relic. Read more about providing a framework that gets you started on the right path to move your IT services to cloud computing, and give you an understanding as to why certain applications should not move to the cloud.


Published at DZone with permission of Daniel Doubrovkine .

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}