Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create HAL representer #1

Open
mikaa123 opened this issue Jun 11, 2014 · 2 comments
Open

Create HAL representer #1

mikaa123 opened this issue Jun 11, 2014 · 2 comments

Comments

@mikaa123
Copy link
Owner

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
Copy link
Owner Author

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
Copy link
Owner Author

Or even simpler:

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

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant