-
Notifications
You must be signed in to change notification settings - Fork 49
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
How to follow multiple relations from a resource? #7
Comments
Thanks for your input. I think this are very interesting ideas and they also match the general "philosophy" of Traverson as a tool to make following links in Hypermedia APIs as easy as possible. Of course, a feature like this would require a major part of Traverson to be rewritten. I'll probably won't get around to do this anytime soon. I would like to keep this open though and I might come back to this later. Also, if someone else would like to take a stab at this I wouldn't mind. We can also discuss API ideas here. I really like the power that the requestSpec thing would give users (the snippet you prefixed with "Going off into total fantasy for a moment"). The downside to this would be that it's much harder to use and understand than the current API. |
Thanks for the reply! I did a quick and dirty implementation of the proposed client for an API-backed app I'm working on over at holderdeord/hdo-front (see e.g api.js where it's used). I've made it so that the "composed" response is basically a big HAL object where the requested relations are always present in This works OK, but it also feels like I'm specifying the rel structure twice - once for the |
+1 for this. It'd be nice to have a continuation option from the promise itself. For example:
|
I finally started to work on 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. |
Continuing link traversals has landed in 2.0.0, which should also enable the use case described in the original ticket. |
Hi, and thanks for your work on this project! I'm a bit new to both node and hypermedia, so bear with me.
I'm trying out traverson for a HAL API I'm building, but can't figure out a good way of following multiple relations from a resource. Using the
orders
example, I may want to fetch both theea:basket
andea:customer
relations of the order I've just found.These are the only ways to do it that I've found (code untested):
a. start from the root resource for every relation
b. create a new traverson instance based on the
order
responseHere's a few ideas on how these could be made simpler:
c. re-use request with additional
.follow
calls (actual requests equivalent to ex. a)d. have the resource object double as a client (actual requests equivalent to ex. b)
All of these feel suboptimal in different ways, both when it comes to performance (number of requests) and readability. It also seems like I'd have to do quite a bit of trickery to get a composed response object (consisting of order, basket and customer) that could be passed to a view or presenter. Though that may also just be my lack of node experience.
Going off into total fantasy for a moment, what I'm really after is a way of specifying all the relations I want up front, and simply get a composed response back. It'd have to be a quiet generic specification to support all the cases, but e.g. something like this:
Or possibly sugar it a bit
Perhaps something like this could be built on top of traverson. Any thoughts?
The text was updated successfully, but these errors were encountered: