Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Content negotiation #58

darvin opened this Issue · 2 comments

2 participants


From my understanding it's impossible to do via connect/express middleware, and it could be nice addition to zappa.

@get '/': ->
  @render index: {foo: 'bar'}

And if request has header Accept-type: application/json, server will respond with JSON {"foo":"bar"} instead of view index rendered with {foo:"bar"}
Will it be accepted into upstream? If yes, I can do that


Sounds cool. I like how Rails handle this. It allows for more fine-grained responses.

if err then @next err

  json: =>
    @jsonp user.toJSON()
  html: =>
    @render index: user.toJSON()

Note that you can just implement this as a helper, no need to integrate this into zappa:

# Call fn if fn is a function
call = (fn, ctx, args...) -> if typeof fn is 'function' then fn.apply(ctx || this, args)

@helper format: (o) ->
  switch @request.get 'Content-Type'
      when 'application/json' then call o.json
      when 'text/html' then call o.html

oh, cool! thanks

@darvin darvin closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.