Goliath + Grape + Aroundware questions

68 views
Skip to first unread message

Winston Teo

unread,
Oct 17, 2013, 5:51:10 AM10/17/13
to golia...@googlegroups.com
I have a simple demo app like so:

ENV['RACK_ENV'] ||= 'development'

require 'bundler'
Bundler.require(:default, ENV['RACK_ENV'].to_sym)

class MyGrape < Grape::API
  format :json
  default_format :json

  get :hello do
    {hello: "world"}
  end
end

class MyBarrier
  include Goliath::Rack::BarrierAroundware

  def pre_process
    raise Goliath::Validation::Error.new(400, 'This should be json') if env["params"]["x"]

    return Goliath::Connection::AsyncResponse
  end
end

class App < Goliath::API
  use Goliath::Rack::Render, 'json'
  use Goliath::Rack::Params
  use Goliath::Rack::BarrierAroundwareFactory, MyBarrier

  def response(env)
    MyGrape.call(env)
  end
end

and I run the app with:

ruby -rgoliath app.rb -sv

I have a few questions about the output:

1. When I issue "curl localhost:9000/hello", I get "#<Rack::BodyProx%". 
Why is that so? Is Goliath json response not playing nicely with Grape's json formatter?
I need both because I would like Grape to return json responses and Goliath to raise json errors.
What is the common way to do this?

2. When I issue "curl localhost:9000/hello?x=1", I get {"error":"This should be json"}" in the console which is what I expect.
However, if I do "localhost:9000/hello?x=1" in my browser, I get [:error, "This should be json"].
I believe that this has something to do with the Accept header. Is there a way to force all browser views to be a json response?

I am using Goliath 1.0.3 and Grape 0.6.0.

Thanks in advance!

Cheers,
Winston

Ilya Grigorik

unread,
Oct 17, 2013, 9:32:31 AM10/17/13
to golia...@googlegroups.com
Does Grape depend on old router? If so, you can try freezing Goliath at older version to see if it works.. 

(I haven't followed Grape, so not sure if anything could have changed there).

ig



--
You received this message because you are subscribed to the Google Groups "Goliath.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to goliath-io+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Winston Teo

unread,
Oct 17, 2013, 12:13:53 PM10/17/13
to golia...@googlegroups.com
Does Grape depend on old router? If so, you can try freezing Goliath at older version to see if it works.. 

Thanks for the prompt reply Ilya! I don't think Grape depends on the old router though, but I'll test it out.

What about (2)? That doesn't really seem to be Grape related. Is that the intended behavior for Goliath?

I'll also cross post this on the Grape Google Group to see if anyone has any idea about this.

Thank you!


Reply all
Reply to author
Forward
0 new messages