-
Notifications
You must be signed in to change notification settings - Fork 1
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
Traversing collections & paginated collections? #7
Comments
traverson-hal supports collections/multiple links with the same relation. From the docs:
There is no special support for paginated collections with |
I'm interested in where this goes as well. I think that my initial thought would be that, if a match was not found under |
That sounds like a pretty reasonable strategy and a nice feature for traverson-hal. Right now, I'm just not completely sure about the specifics. I'll give an example to explain where I'm a bit confused: If one document had some Can we come up with a concrete example, that is, one or two hal documents, an example Traverson snippet that works with this API and the expected result of the Traveson call? |
Hey, sorry I didn't get back to you on this, totally forgot I mentioned it until I saw an email this morning! I was talking about a resource like the one on page 7 of the hal spec, reproduced below with only the pagination details:
Given a resource like this, I have items (which may be resources or not, embedded or not), and I can tell there's a next page in the collection by the presence of a I might want to do something with every item in the collection - say compute the average total or log all the totals to a report for the example doc above. I hadn't considered the find or filter operation that @travi mentioned (if I understood correctly) but I imagine you'd need to still check each item and page forward the same way. So I'm wondering what a great client API would look like - I think ideally the client could totally ignore pagination - it can just iterate over items and paging happens if needed, maybe something like a forEach, map, reduce? |
Oh, I didn't know that using embedded docs for the collection pattern was officially endorsed by the spec. So yeah, let's discuss APIs. I think there are two only loosely related proposals here in this thread:
|
Hi, Given the following resource, where the number of orders is unknown before retrieval, how can I get and iterate over all the linked customer resources? Is it possible with Traverson at all without dealing with _links myself? {
"_links": {
"self": { "href": "http://sample.org/orders" }
},
"_embedded": {
"orders": [
{
"_links": {
"self": { "href": "http://sample.org/orders/1" },
"customer": { "href": "http://sample.org/customers/91" }
}
},
{
"_links": {
"self": { "href": "http://sample.org/orders/2" },
"customer": { "href": "http://sample.org/customers/92" }
}
}
]
}
} |
@trombka Wait, I misunderstood you, I think. You want an array of the resources at http://sample.org/orders/1, http://sample.org/orders/2, ..., so, in effect, you want traverson to make all these requests and then come back to you with an array of the collected results. This is currently not possible, I'm afraid. It would be an interesting feature, too, I think. |
@basti1302 Of course it would be nice to have such collection deep traversal supported by the library, but I think it would good enough to somehow continue traversal from each collection item. A method to start traversal from a resource would do, I think. traverson
.from('http://sample.org/orders')
.follow('orders[$all]')
.getResource(function (error, orders) {
orders.forEach(function (order) {
traverson.from(order).follow('customer'); // 1
traverson.from(order._links.self.href).follow('customer'); // 2
traverson.from(order._links.customer.href) // 3
});
});
|
+1 |
Hi there, nice library!
Does traverson support traversing a collection of items with the same rel? Even better, a paginated collection following "next" links? (I'm thinking of HAL here eg. http://stateless.co/hal_specification.html, "Representing Multiple Links With The Same Relation")
I couldn't see anything in the documentation mentioning collections like this so I thought I'd ask!
The text was updated successfully, but these errors were encountered: