mikaa123 / catnap

Simple Resource-oriented architecture for node
MIT License
75 stars 5 forks source link

Create HAL representer #1

Open mikaa123 opened 10 years ago

mikaa123 commented 10 years ago

I <3 HAL and I use it a lot. Instead of having to manually create "links" and "embedded", it could be useful to have a representation strategy for it.

mikaa123 commented 10 years ago

something along these lines:

halRepresenter(function (hal, entity) {
    var res = {};

    hal.links(res, [
        aResource,  // Use the resource's name for rel, and the resource's path
        { 'rel': anotherResource } // Custom rel
    ]);

    hal.embedded(res, { posts: posts });

    return res;
});
mikaa123 commented 10 years ago

Or even simpler:

halRepresenter(function(res, entity) {
    res.attributes({
        'count': 3
    });

    res.embedded({
        'users': ['foo']
    });

    res.links({
        'bar': 'baz'
    });
})