Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Content negotiation #58

Closed
darvin opened this Issue · 2 comments

2 participants

@darvin

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

@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

@Radagaisus

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

if err then @next err

@format
  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
@darvin

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.