Currently requests support multiple formats (html, js, pdf, xml) with
the default format being html.
For example, a request to
http://myapp.com/user/show/1 will output the
view as html, but requests to
http://myapp.com/user/show/1.pdf or
http://myapp.com/user/show/1?format=pdf will output the view as a pdf.
For js and xml formats, your actions need to opt-in using the @formats
annotation on the action. For example, if you want your action to
support only html and xml format, you'd set "@formats html, xml" on
your controller's action.
Also, for js and xml formats, the params are automatically serialized
and output for you by default. If you want to change that, you can
create a format-specific view for outputting your response simply by
creating a new view with a format-specific extension. For example, if
you create a view located at /views/user/show.xml.cfm, it will be
automatically rendered for calls to
http://myapp.com/user/show/1.xml
rather than just outputting the serialized params. This can be
important if you don't want to fully serialized your entities and
instead only return certain properties for certain requests.
When it comes to js reponses, what would people prefer the suffix to
be. Currently it's "js", so
http://myapp.com/user/show/1.js will
return a JSON-serialized response and /views/user/show.js.cfm will
render a format-specific view. I think this makes the sense, but would
people prefer it to be "json" instead of "js"? I think I prefer /user/
list.js, but user/list?format=json. Currently ColdMVC checks to see if
the format is json and switches it to js instead, but does that make
the most sense? Should calls to getFormat() return "js" or "json"?