bleupen / halacious

a better HAL processor for Hapi
MIT License
108 stars 22 forks source link

Custom `_self` link generator #89

Closed felixheck closed 5 years ago

felixheck commented 8 years ago

Hi there!

I am currently looking for an approach to customize the _self link. On the one hand I want, that all query parameters of the request will be appended. I do not wanna define them explicitly. Is there a possible and smart way with halacious?

On the other hand I want to strip query parameters depending on their value. For example page=1 should be stripped because 1 is the default of page. Is there a way to define a custom link generator? This would solve perhaps the first issue too.

Nevertheless thanks for your work, I love the Plugin :)

felixheck commented 8 years ago

Alternatively I would like to "override" the self link with a custom one. If I do so at the moment, the self become an array :/

felixheck commented 8 years ago

@bleupen There won't be a feature like that in the near future or will it? Just wanna know because of a new project :)

bleupen commented 8 years ago

You can set it in the prepare function. Will this work for you?

server.route({
    method: 'get',
    path: '/hello/{name}',
    config: {
        handler: function (req, reply) {
            reply({ message: 'Hello, ' + req.params.name });
        },
        plugins: {
            hal: {
                prepare: function (rep, done) {
                    rep._links.self.href = '/foo/bar';
                    done();
                }
            }
        }
    }
});