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