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

Feature Request: Traversable Nodes #4

Closed
marartner opened this issue Mar 5, 2015 · 3 comments
Closed

Feature Request: Traversable Nodes #4

marartner opened this issue Mar 5, 2015 · 3 comments

Comments

@marartner
Copy link

Hey there. We had an R&D day in our company last week and (as you noticed) took an early look at Traverson as potential new tech to use in future projects, and again now after release, and we kinda liked what we were seeing. However, we think Traverson does not seem to unleash its full potential yet, and wanted to let you know about our findings:

In our particular case, we wanted to explore a JSON+HAL API. For that one, we did not now the complete structure in advance, and had to go through it step by step, exploring which links there are, and then deciding for each step which link to follow. Think of it as an maze api, each step reveals a new field in the maze with some field info and a couple of links to follow ("east", "west", "ladder", etc...) and you won't be able to know in advance in which directions you'll be able to go, which possible links you'll be able to follow after each step, so doing api.follow('east', 'south', 'west') isn't possible right from the start. Also, we did not want to use the actual hrefs, we wanted to traverse only by follow()-ing link-names.

Now using Traverson, we would have to always start from the first step (api-root), and then follow() the individual paths we already discovered, and upon discovering a new field, start from root again and retrace our steps plus the new one. And Traverson makes a request for every single step on the way, requesting the same "fields" again and again. For a little R&D Fun, or projects where you know the structure in advance, thats okay, but for future projects that need more optimisation, that's kinda awkward. A little workaround (breaking the no-href-rule) was to treat each step as a new root, but even then, Traverson still makes 2 requests instead of just one (the current field, plus the one we are follow()-ing)

So, what we would love to see would be that, after follow()-ing a link of our HAL-API, we'd not just get the actual data of that new resource, but some kind of API-Node/Response-Object that knows its own data and is able to follow its own links without making another request to itself, only to the new link-url, in turn giving us yet another API-Node/Response-Object, that again knows its own data, but also allows us to traverse even further with just a single request.

I don't think that is possible with Traverson / Traverson-HAL as it is - correct me if I'm wrong. But we think it might be a great way to improve your project, and something we'd love to see done. So, any chance you could so something like that?

@basti1302
Copy link
Member

Something along these lines has come up here and there in the traverson repository. It's related to traverson#24 and traverson#7.

I definitely want to have something like that in Traverson. It's one of the main features that should go into a new major version. I have not given it enough thought yet, I think the challenge is to come up with an API that is still intuitive enough to use but can handle all these slightly different use cases in the same fashion.

Also, the internal code of Traverson has become a bit too complicated for my taste as of lately. I think it needs a thorough refactoring before implementing any major new features.

That said, I think discussions about a feature like this should happen in the traverson repo, not in traverson-hal. traverson-hal is really only a little plug-in to make traverson deal with application/hal+json.

@basti1302
Copy link
Member

I started to work continuing traversals in this branch (better late than never, right? ;-) ). I'd love some feedback on the API (which is work in progress right now), so chime in to the discussion at issue #40 if you like.

@basti1302
Copy link
Member

Continuing link traversals has landed in 2.0.0.

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

2 participants