Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON API compatibility #144

jfelchner opened this issue Sep 30, 2015 · 14 comments

JSON API compatibility #144

jfelchner opened this issue Sep 30, 2015 · 14 comments


Copy link

@jfelchner jfelchner commented Sep 30, 2015

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]
Copy link

@gte451f gte451f commented Oct 9, 2015

+1 All hail JSON API

Copy link

@drewclauson drewclauson commented Oct 14, 2015


Copy link

@avanov avanov commented Oct 16, 2015

+1. Really looking forward to it.

Copy link

@mharris717 mharris717 commented Oct 20, 2015

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.

Copy link

@broerse broerse commented Oct 20, 2015


Copy link

@sarus sarus commented Oct 25, 2015

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.

Copy link

@sarus sarus commented Oct 26, 2015

@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

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: ^

----- 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.

Copy link

@jfelchner jfelchner commented Oct 26, 2015

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

Copy link

@broerse broerse commented Oct 26, 2015

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

Copy link

@jcope2013 jcope2013 commented Nov 25, 2015

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

Copy link

@ryrych ryrych commented Jan 11, 2016

@jfelchner hi, any update on this?

Copy link

@MrDinsdale MrDinsdale commented Mar 10, 2016

+1 Anyone have a good work around for this?

Copy link

@robertoplancarte robertoplancarte commented Jun 30, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet