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

Open
jfelchner opened this Issue Sep 30, 2015 · 14 comments

Comments

Projects
None yet
@jfelchner
Copy link

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]
@gte451f

This comment has been minimized.

Copy link

gte451f commented Oct 9, 2015

+1 All hail JSON API

@drewclauson

This comment has been minimized.

Copy link

drewclauson commented Oct 14, 2015

+1

@avanov

This comment has been minimized.

Copy link

avanov commented Oct 16, 2015

+1. Really looking forward to it.

@mharris717

This comment has been minimized.

Copy link
Owner

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.

@broerse

This comment has been minimized.

Copy link
Collaborator

broerse commented Oct 20, 2015

👍

@sarus

This comment has been minimized.

Copy link

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.

@broerse

This comment has been minimized.

@sarus

This comment has been minimized.

Copy link

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

@jfelchner

This comment has been minimized.

Copy link

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.

@broerse

This comment has been minimized.

Copy link
Collaborator

broerse commented Oct 26, 2015

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

@jcope2013

This comment has been minimized.

Copy link
Contributor

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

@ryrych

This comment has been minimized.

Copy link

ryrych commented Jan 11, 2016

@jfelchner hi, any update on this?

@MrDinsdale

This comment has been minimized.

Copy link

MrDinsdale commented Mar 10, 2016

+1 Anyone have a good work around for this?

@robertoplancarte

This comment has been minimized.

Copy link

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