Giter Site home page Giter Site logo

Comments (11)

nicolaiarocci avatar nicolaiarocci commented on July 23, 2024

Need to figure out a good way to return the total item count, as _items is just a list of documents (and as you say won't be accurate when paginated). Maybe by using some X- custom header... or adding an additional [metadata] item to the payload (not liking this one much, as we already have both _items and _links). Will do some brainstorming on this - thanks!

from eve.

nicolaiarocci avatar nicolaiarocci commented on July 23, 2024

I came out with 2 possible solutions for this, both REST-compliant:

  1. Use a custom X-Pagination-Total-Count header which would simply return the total number of records for the query, possibly paired with X-Pagination-Current-Page, X-Pagination-Per-Page.

  2. Rename the _links dictionary to _metadata and add new keys to it: total_count, per_page, etc. This would break backward compatibility but I wouldn't worry much about it because 1) we're still in alpha after all and 2) the change is trivial.

I'm tending towards the second option because it would also allow for future expansion, like adding more metadata as needed. Opinions?

from eve.

flaper87 avatar flaper87 commented on July 23, 2024

I'd suggest using link headers. A good example is GH's ussage[0]. Here's the RFC[1]

[0] http://developer.github.com/v3/#pagination
[1] http://tools.ietf.org/html/rfc5988

from eve.

nicolaiarocci avatar nicolaiarocci commented on July 23, 2024

@flaper87 that would be an alternative way to handle pagination links themselves, which are already supported even though with a slightly different format (see HATEOAS). I explored that rfc a few days ago but it does not seem to provide any directive about handling the actual query record count, which is what this ticket is really about.

from eve.

mario avatar mario commented on July 23, 2024

If we must have this, I'd prefer X-Pagination-Total-Count approach.

from eve.

flaper87 avatar flaper87 commented on July 23, 2024

@nicolaiarocci But, is it really needed? I mean, having the last page should be enough, right?

What about adding page to the link dictionary and adding first and last? The idea is to keep the API as consistent as possible.

_NOTE:_ I'm not sure the page key is actually needed once you have the link to the last page, it might be, though.

"_links": {
    "self": {
        "href": "localhost:5000/people/",
        "title": "people"
    },
    "parent": {
        "href": "localhost:5000",
        "title": "home"
    },
    "next": {
        "page": 2,
        "href": "localhost:5000/people/?page=2",
        "title": "next page"
    },
    "last": {
        "page": 100,
        "href": "localhost:5000/people/?page=100",
        "title": "last page"
    }
}

from eve.

nicolaiarocci avatar nicolaiarocci commented on July 23, 2024

That's an interesting approach indeed. Let's see what's the OP use case if any.

from eve.

nicolaiarocci avatar nicolaiarocci commented on July 23, 2024

The idea is to keep the API as consistent as possible.

Precisely, that's why I'm so torn on this one. I find that your suggestion is as consistent as it can get. Thanks!

from eve.

jdm avatar jdm commented on July 23, 2024

I had a couple use cases in mind - sometimes I'd like to display one page of results at a time, and have the usual "1 .. 4 [5] 6 .. 98" link display. Other times I want to be able to load all results progressively, and display some kind of useful status to user (X of Y results).

from eve.

mario avatar mario commented on July 23, 2024

Afaik having the last page would solve this problem :)

from eve.

nicolaiarocci avatar nicolaiarocci commented on July 23, 2024

@jdm thought so. I guess I'll go ahead and implement @flaper87 solution (minus the page as it should not be needed). In any case, we can always add a X-Total-Count header.

from eve.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.