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

plugin.location #1767

Closed
jeffm13 opened this issue Jul 9, 2014 · 6 comments
Closed

plugin.location #1767

jeffm13 opened this issue Jul 9, 2014 · 6 comments
Assignees
Labels
feature New functionality or improvement
Milestone

Comments

@jeffm13
Copy link

jeffm13 commented Jul 9, 2014

Any plans for a plugin.location function that combines the server.location() value with the plugin route prefix?

@hueniverse
Copy link
Contributor

What's the use case?

@jeffm13
Copy link
Author

jeffm13 commented Jul 16, 2014

Generating _link (HAL style hyperlinks) inside a resource generated by a plugin. For example, a customer resource generated by a plugin with a prefix of:

    server.pack.register({
        plugin: require('mycustomer'),
 }, { prefix: '/myCustomerService/v1' }, function() ...

with a route:

   { method: 'GET', path: '/customers', handler: ... }

should look like this:

{
    'name': 'John Doe',
    '_links': {
        'rel': 'self',
        'href': '/myCustomerService/v1/customers/123456'
    }
}

I could kludge a way to pull it from the request uri, but it would be more convenient if I could pull the prefix from the plugin itself.

@hueniverse
Copy link
Contributor

Wouldn't that logic happen inside a handler? Why can't you just use request.path?

@jeffm13
Copy link
Author

jeffm13 commented Jul 16, 2014

Yes the logic happens inside a handler. I simplified the use case to show only a 'self' link, but I've got multiple routes that can be used for this resource--all of which are entries in the plug-in's route table. My thought was to construct the _links by traversing the route paths. But to provide the complete href for each route, I'd need to know the plug-in route prefix.

I could parse the request.path, but that feels like a kludge. I could also pass the prefix as an option to the plugin--probably an easier solution, but also not ideal. If the plugin had a location method (or at least a way to access its prefix) it would make for a cleaner implementation.

@hueniverse hueniverse added this to the 6.2.0 milestone Jul 17, 2014
@hueniverse hueniverse self-assigned this Jul 17, 2014
@bleupen
Copy link

bleupen commented Jul 18, 2014

You might consider using my hal library for hapi:

https://www.npmjs.org/package/halacious

@Marsup Marsup added feature New functionality or improvement and removed request labels Sep 20, 2019
@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New functionality or improvement
Projects
None yet
Development

No branches or pull requests

4 participants