class UsersCreate < Goliath::API use Goliath::Rack::Render, 'json' use Goliath::Rack::Params use Goliath::Rack::Validation::RequiredParam, {:key => 'token',
:message => 'is required'} end
If no "token" param, Goliath returns "[:error, \"token is required\"]". Since I've included the Render middleware, shouldn't the output be in json?
On Mon, Aug 20, 2012 at 2:13 AM, sent-hil <senthil...@gmail.com> wrote:
> class UsersCreate < Goliath::API
> use Goliath::Rack::Render, 'json'
> use Goliath::Rack::Params
> use Goliath::Rack::Validation::RequiredParam, {:key => 'token',
> :message => 'is required'}
> end
> If no "token" param, Goliath returns "[:error, \"token is required\"]".
> Since I've included the Render middleware, shouldn't the output be in json?
Yes, but it also depends on what you're using to send the request.. If your
client is specifically asking for text/plain, then that's what you'll get.
On Mon, Aug 20, 2012 at 10:36 AM, Ilya Grigorik <igrigo...@gmail.com> wrote:
> Yes, but it also depends on what you're using to send the request.. If
> your client is specifically asking for text/plain, then that's what you'll
> get.
Goliath::Rack::Render only sets the Content-Type header (and sets the Vary header to the value of the Accept header in the request).
Use that with Goliath::Rack::Formatters::JSON to get closer to the results you want.
Keep in mind that these are mechanisms of Content Negotiation (http://en.wikipedia.org/wiki/Content_negotiation) and can depend on the Accept header being sent asking for `application/json` data to be returned.
On Monday, August 20, 2012 at 12:54 PM, sent-hil wrote:
> But if its blank I should get a json response right? I'm not seeing that.
> On Mon, Aug 20, 2012 at 10:36 AM, Ilya Grigorik <igrigo...@gmail.com (mailto:igrigo...@gmail.com)> wrote:
> > Yes, but it also depends on what you're using to send the request.. If your client is specifically asking for text/plain, then that's what you'll get.
class UsersCreate < Goliath::API
use Goliath::Rack::Formatters::JSON
use Goliath::Rack::Render, 'json'
use Goliath::Rack::Params
use Goliath::Rack::Validation::RequiredParam, {:key => 'token',
:message => 'is required'}
def response(env)
[200, {'Content-Type' => 'application/json'}, {response: 'user
created'}]
end
end
With the above code, if I do `curl -H "Accept:application/json" "
http://localhost:8000"` shouldn't I be seeing {'error' => 'token is
required'}? Instead I still see [:error, "token is required"].
I included JSON formatter and specified 'Accept' header, not sure what's
going on here.
Interestingly enough, we did have a guard for duplicate middlewares in pre 1.0 release, but dropped that as part of refactoring.. May be worth taking another look.
On Tuesday, August 21, 2012 8:38:05 PM UTC-7, sent-hil wrote:
> class UsersCreate < Goliath::API > use Goliath::Rack::Formatters::JSON > use Goliath::Rack::Render, 'json' > use Goliath::Rack::Params > use Goliath::Rack::Validation::RequiredParam, {:key => 'token',
> With the above code, if I do `curl -H "Accept:application/json" " > http://localhost:8000"` shouldn't I be seeing {'error' => 'token is > required'}? Instead I still see [:error, "token is required"].
> I included JSON formatter and specified 'Accept' header, not sure what's > going on here.