Comments (11)
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.
I came out with 2 possible solutions for this, both REST-compliant:
-
Use a custom
X-Pagination-Total-Count
header which would simply return the total number of records for the query, possibly paired withX-Pagination-Current-Page
,X-Pagination-Per-Page
. -
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.
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.
@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.
If we must have this, I'd prefer X-Pagination-Total-Count approach.
from eve.
@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.
That's an interesting approach indeed. Let's see what's the OP use case if any.
from eve.
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.
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.
Afaik having the last page would solve this problem :)
from eve.
@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)
- Is there a way to get jsonschema using the API? HOT 1
- Issue with query_objectid_as_string on Eve>=1.0.1 HOT 7
- Release HOT 1
- 422 UNPROCESSABLE ENTITY when using user_id and data_relation on PATCH HOT 1
- Render fails because recent version of Werkzeug has removed escape() method from utils HOT 6
- HATEOAS links are relative starting with Werkzeug 2.1; should be absolute for backward compatibility HOT 1
- Werkzeug utils has no attribute escape. HOT 1
- MongoDB auth related issue in MONGO_URI HOT 10
- Add support to release Linux aarch64 wheels HOT 2
- deleteitem_internal on media resource, KeyError: 'media'
- Tests fail with Flask 2.2 HOT 2
- etag generation fails if 'uuidRepresentation' is not set in MONGO_OPTIONS HOT 1
- Malformed Last Updated field HOT 7
- How to get in touch regarding a security concern HOT 1
- [Feature Request] One document Endpoint HOT 1
- pass var to a pipeline aggregation via url and regex HOT 1
- Replace vs Merge Update on PATCH
- CI failure: `mongo command not found` on ubuntu-latest (22.04)
- Tests folder in eve distribution HOT 3
- Type serialization does not work inside valuesrules or valueschema
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eve.