Problem/Motivation
Postponed on #2100637: REST views: add special handling for collections
Link relations are used to point to next steps when using a REST API. A common use case for REST link relations is pagination through collections. For example, you can use the IANA link relations such as next and previous, as follows:
Link: <http://example.iana.org/collection/1>; rel="first",
<http://example.iana.org/collection/100>; rel="last",
<http://example.iana.org/collection/3>; rel="next",
<http://example.iana.org/collection/2>; rel="previous",
Views is our tool for producing collections. We should add pagination to that.
Proposed resolution
TBD
Remaining tasks
Determine where this should be added
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | 2099281_views_rest_pagination-15.patch | 2.5 KB | richardbporter |
| #3 | 2099281_views_rest_pagination.patch | 2.64 KB | sepgil |
Comments
Comment #1
sepgil commentedAfter a short talk with klausi, we agreed that we need to add the pagination into the serializers, since each format may or may not define where to list the links. So for hal+json it would be in an object called '_links' which contains sub-objects like next, previous and so on, similar to the link objects for the entites. See the example in the hal+json specification.
Therefore I would suggest to implement the pagination for hal+json first. Later we can decide if and how we should implement for other formats.
Comment #2
linclark commentedYes, I agree. We could potentially also add the links using the HTTP Link header, but for hypertext-aware formats such as HAL we should also include the links directly in the message body.
Comment #3
sepgil commentedYeah, you are right. I haven't thought of adding the links to the HTTP headers...
Here is a first, very hacky patch, which will simply add the links directly into the top array through the serializer style plugin. It shouldn't be to complicated however, to use this functionality so that we can add the links to the headers.
The more complex problem is how to pass the links to the correspondent format serializer, so that it can process them. I've tried looking into that, but I don't have the insights on symfony and the whole serialization stuff to implement that.
Comment #4
linclark commentedUnfortunately, I don't think we can do it at this level. It requires the Serializer to know too much about the format that it is outputting.
Comment #5
linclark commentedI forgot that I had started on something called an EntityCollection when we were in Portland. I think that adding the EntityCollection normalizer would give us a place to handle pagination. See #2003108: Switch Views RSS to use Serializer/Zend
Comment #6
klausiSee also #2100637: REST views: add special handling for collections.
Comment #7
clemens.tolboomI could use some help @ #2100637: REST views: add special handling for collections and probably make this issue a duplicate one.
This one is at least postponed on #2100637: REST views: add special handling for collections
Comment #8
wim leersI don't see why this is blocked on #2100637: REST views: add special handling for collections?
Comment #9
wim leers#2573557: REST views: Paging-related URLs should be returned in "_links" section of HAL+JSON response was marked as a duplicate of this (and was opened almost exactly two years after this one).
Comment #10
dawehnerWell, that issue actually implements this issue or at least would be certainly required to make any progress here.
Comment #11
wim leersOh, I see, because we don't even have such pagination REST URLs working right now, so even though we could add
Linkheaders, we'd have no URLs to point to.Comment #12
dawehnerExactly.
Comment #13
simone960 commentedReally need this pagination feature. Hope this can be added to 8.1 later
Comment #15
richardbporter commentedI've got a use case for this functionality. I'm not exactly sure how it relates to #2100637 but I've re-rolled this patch against 8.2.x because #3 seemed not to apply anymore. I had trouble generating an interdiff from #3 as well.
Comment #16
richardbporter commentedI'm sorry - I just noticed the status was marked as postponed. I think my last patch can be disregarded.
Comment #17
clemens.tolboomComment #20
wim leersComment #23
wim leersClosed #2944196: How to do pagination on collections using core REST modules as a duplicate.
Comment #33
smustgrave commentedBlocker seemed like it landed a while ago.