0

I know restify does not ship with render capabilities because the responses are handled in the controller, but Ive found myself changing lots of stuff in the controllers that could be easily maintained by having the JSON responses rendered.

So I was wondering how to render restify JSON responses with a template such as mustache or jade, and handle the views (controller responses) separated from the controllers, for better maintenability of the API.

maumercado
  • 1,453
  • 4
  • 23
  • 47
  • Restify is a framework for building APIs, and normally APIs don't have views (or a presentation layer). The biggest advantage of Restify is that it skips views and is leaner. I cannot understand why you want to "render" JSON - it is returned by the controller in the response anyway. "Render" is a term you use for user interface. – Slavo Oct 25 '13 at 11:39
  • Youre right, and I know that restify does not do that.. but in terms of maintainability, sometimes its better to have a view that lets say formats the answer to be sent, in order to not have to change every related controller response everytime something changes, instead, Ill just change the "view". – maumercado Oct 25 '13 at 14:48
  • I am not sure I understand what you mean. There is no format for the answer when talking about an API. There are different protocols and content types, but that falls into the domain of content negotiation. You can use request headers, the URL or any other scheme for this. Why introduce a view? Changing a view and changing the controller are virtually the same in what you describe and I am failing to see the benefit of a view. – Slavo Oct 25 '13 at 15:12
  • Still, I don't want to argue. If you want views - use Express. Restify doesn't have them. – Slavo Oct 25 '13 at 15:14

0 Answers0