ember-cli-pagination icon indicating copy to clipboard operation
ember-cli-pagination copied to clipboard

JSON API compatibility

Open jfelchner opened this issue 10 years ago • 15 comments

Now that ember-data final is in the wild and it's default to JSON API, a lot of people are going to be making moves to make their APIs compatible.

I realize that before JSON API, Kaminari was the best option for defaults, but now I think we should switch to JSON API compatible pagination.

We're currently having to do some crazy param mapping stuff every single place we need to do it and we can't even get the total pages to render properly.

Meta Tag Example for Pagination Metadata

{
  "meta": {
    "page": {
      "offset": 1,
      "limit": 10,
      "total": 35
    }
  }
}

Request Parameters Examples

  • page[number]
  • page[size]
  • page[offset]
  • page[limit]
  • page[cursor]

jfelchner avatar Sep 30 '15 04:09 jfelchner

+1 All hail JSON API

gte451f avatar Oct 09 '15 18:10 gte451f

+1

drewclauson avatar Oct 14 '15 14:10 drewclauson

+1. Really looking forward to it.

avanov avatar Oct 16 '15 09:10 avanov

This needs to get done. I'd like to start on it this week.

Thanks @jfelchner for creating the issue. I'll comment with an update when I have one.

mharris717 avatar Oct 20 '15 19:10 mharris717

:+1:

broerse avatar Oct 20 '15 19:10 broerse

Would love to see this. Would it make sense to somehow use the links property of the payload rather than whatever might be in meta?

The json api doesn't set any standard for what should be in meta but does enforce standard pagination links. Per the json api specification:

The following keys MUST be used for pagination links:

first: the first page of data
last: the last page of data
prev: the previous page of data
next: the next page of data

which means they are always available versus meta which could be anything. I'm not sure if this is exposed at all by ember data though. Just getting started with it.

sarus avatar Oct 25 '15 01:10 sarus

@sarus It seems ember-data expects it to be on meta. See: https://github.com/emberjs/data/blob/4e83729f38a158dc9be9aeff667c513ca070e05c/packages/ember-data/lib/serializers/json-serializer.js#L1206

broerse avatar Oct 25 '15 09:10 broerse

@broerse Not to say that ember data won't make use of the meta field for pagination but I think that function is just a general way to access meta info for any purpose and not necessarily paging (see the guide here http://guides.emberjs.com/v2.1.0/models/handling-metadata/)

I asked on Slack about how Ember Data intends to implement paging and this was the resulting conversation:

sarus [9:18 PM] 
Will the ember data "sugar for pagination" use the pagination links `first`, `last`, `prev`, `next` or will it enforce some specific paging parameters set via the `meta` property?  I ask because the json-api spec says links must have `first`, `last`, `prev`, `next` pagination links but doesn't enforce any specific usage of the `meta` property.  Thanks!

bmac [10:37 PM] 
@tchak: ^
NEW MESSAGES

----- Today October 26th, 2015 -----

awesan [5:27 AM] 
it says in the spec that those `first`, etc. links MUST be used for pagination

awesan [5:28 AM]
so at the very least it will have to use them, maybe it could use more info from meta tags (edited)

awesan [5:38 AM] 
the way I understand the spec it means 'if you do pagination, use these links'

tchak [5:50 AM] 
@sarus @awesan the current plan is to add support for pagination links yes

tchak [5:50 AM]
@awesan: the problem with links, is that they do not allow for the case “go to page 3"

munumnun [5:51 AM] 
that's where url templates could work :simple_smile:

tchak [5:51 AM] 
@munumnun: yes

tchak [5:51 AM]
I was about to say that

tchak [5:51 AM]
but right now there is nothing in the spec about it

tchak [5:52 AM]
would be great to have `n-page` templated link or something

tchak [5:52 AM]
@dgeb ^

munumnun [5:54 AM] 
it's kinda bad because you can't use json hal templated links with data right now without doing some nasty hacks

Based on the conversation it seems like the links property will be used but there appears to be some discussion about what else is needed for things like "jump to page" which will either require use of the meta property of templated links.

sarus avatar Oct 26 '15 13:10 sarus

IMO the API still needs to return both regardless. Parsing "What is the current page?" Out of pagination links is a pain.

jfelchner avatar Oct 26 '15 16:10 jfelchner

@jfelchner @sarus I also think we need both. Now we need something to test against.

broerse avatar Oct 26 '15 18:10 broerse

any progress made here by anyone in their apps or are people just using some ad hoc solutions where they are shaping the objects that get passed into the PagedRemoteArray

jcope2013 avatar Nov 25 '15 20:11 jcope2013

@jfelchner hi, any update on this?

ryrych avatar Jan 11 '16 10:01 ryrych

+1 Anyone have a good work around for this?

MrDinsdale avatar Mar 10 '16 11:03 MrDinsdale

Frank Treacy has a post about this and shows a good workaround; he even links to this thread. Jump to "#1: Accessing pagination links".

robertoplancarte avatar Jun 30 '16 23:06 robertoplancarte

I know this is old, but is there still no solution for pagination in an ember app that adheres to jsonapi-spec?

zion avatar Jul 20 '23 18:07 zion