Hi all,
One of the needs I ran into with restify was fine-grained control of the output of JSON send to clients. Most REST API's query a data store, filter specific objects and then send some representation of those objects back to the client. The exact model objects returned from the data store are rarely formatted properly for client consumption. You almost always need to white list certain properties or add additional meta data. Those tasks are always the same. Public user objects should always look like public user objects regardless of the API endpoint outputting them.
As a solution, we have come up with Jiggler, a lightweight framework for defining object representation templates and then transforming model objects via those templates:
I'd love to more seamlessly integrate Jiggler with Restify and am curious what approach would be best. My intended approach is to add the to-be-transformed object to the request and then add a post-route-definition plugin that tells Jiggler to format that object as the response (so that this function executes after all business logic). Any thoughts on this or possible better alternatives?
Thanks!