question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ensure works with JSONAPI pagination requirements

See original GitHub issue

I’m a bit new to JSONAPI, but it looks like the meta key goes away and becomes the links key. I tried the new JSONAPIAdapter and doesn’t look like this addon plays well with it. Perhaps we can first make the response format overridable, to make the user handle the links key themselves and transform it into something we expect. We could also sniff the adapter and try to pick the response format automatically.

Comments welcome because this is just the beginning of my thoughts.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:34 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
Duder-onomycommented, Aug 8, 2017

Got this working in our implementation. We have a rails backend using jsonapi-resources and the ‘Paged Paginator’.

The only gotcha in our implementation was that we did not expose the total pages count to the client, probably a similar issue to what @allthesignals was having. Ember Inifinity would only request one page, or keep requesting pages until I would kill the ember server. We had to explicitly allow the page count in the meta field like so: top_level_meta_include_page_count

The ember route looks like so:

import BaseRoute from 'shared-components/routes/base';
import InfinityRoute from 'ember-infinity/mixins/route';

export default BaseRoute.extend(InfinityRoute, {
  perPageParam: 'page[size]',
  pageParam: 'page[number]',
  totalPagesParam: 'meta.page-count',

  model() {
    return this.infinityModel('media-item', {
      perPage: 20,
      startingPage: 1,
    });
  },
});

works great! good job Ember Infinity team. Since jsonapi seems to the the preferred format for ember and the default for ember-data, I think something alluding to this should be in the readme. My opinion.

2reactions
ashikodescommented, Jan 26, 2016

I see It can work with jsonapi pagination.

perPageParam: "page[size]",              // instead of "per_page"
  pageParam: "page[number]",                  // instead of "page"
  totalPagesParam: "meta.total",    // instead of "meta.total_pages"

total pages was calculated and sent with the metadata as

meta: {
     total: 5
}

And it works smooth

Read more comments on GitHub >

github_iconTop Results From Across the Web

“Cursor Pagination” Profile - JSON:API
On any valid paginated request, the number of pagination items returned MUST equal the used page size — provided there are at least...
Read more >
Support paging · Issue #236 · json-api/json-api - GitHub
We can make mandatory the addition of the hash of the body to the URL: if a request come with an -incorrect hash...
Read more >
JSONAPI Elixir — jsonapi v1.4.0 - HexDocs
JSONAPI.Deserializer is a plug designed to make a JSON:API resource object more convenient to work with when creating or updating resources. This plug...
Read more >
Pagination - Laravel JSON API
JSON API designates that the page query parameter is reserved for paging parameters. However, the spec is agnostic as to how the server...
Read more >
Pagination in Ember with a JSON API Backend
Consuming the paginated API. Let's assume we have a working backend. If you don't have a compliant backend, here is a quick Rails...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found