imJohnBon's avatar

Fractal Paginating Subresources

I'm currently working on integrating Fractal into an API Lumen project.

However, I have a question about paginating embeds. Let's say we have API response for books that also has a sub-embed for the books authors:

{
    "data":  [
        { "id": 11 },
        { "id": 12 },
        { "id": 13 },
        { "id": 14 },
        { "id": 15 }
        "authors":  [
            "data": [
                { "id": 14 },
                { "id": 15 },
                { "id": 16 }
                { "id": 17 }
                { "id": 18 }
            ],
            "meta": {
                "pagination": {
                    "previous": 5,
                    "current": 10,
                    "next": 15,
                    "count": 5
                }
            }
        ]
    ],
    "meta": {
        "pagination": {
            "previous": 5,
            "current": 10,
            "next": 15,
            "count": 5
        }
    }
}

Fractal has pretty great documentation on setting up pagination, but I don't see anything on how I would create a URL to paginate the "authors" embed there, which has it's own pagination. Anyone done this?

0 likes
2 replies
imJohnBon's avatar

Heads up for anyone in the future who finds this thread via Google or something, I tweeted this question to the book author (Phil Sturgeon) and here was his response:

"add a link to /authors with whatever query string items need to be there. " https://twitter.com/philsturgeon/status/732222938825560064

Basically, the sub-resource should have it's own pagination URL that would be called if the user tried to paginate the sub-resource. This new request would only return the sub-resource results. Pretty simple really, was over complicating it in my head thinking that for some reason you would keep hitting the original resource endpoint for more sub-resources.

lara30453's avatar

@imJohnBon Thanks for doing the digging!

Could you elaborate on how you would go about doing this? would I return, let's say 4 authors and if I wanted more I would hit another URL to get them paginated?

Please or to participate in this conversation.