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

Is there a way to paginate the results? i.e. ?page=1 or ?limit=10 #65

Open
alex2118 opened this issue Apr 27, 2018 · 9 comments
Open

Is there a way to paginate the results? i.e. ?page=1 or ?limit=10 #65

alex2118 opened this issue Apr 27, 2018 · 9 comments

Comments

@alex2118
Copy link

alex2118 commented Apr 27, 2018

Is there a way to paginate the results? i.e. ?page=1 or ?limit=10

@alex2118 alex2118 changed the title Is there a way to paginate the results? i.e. ?page=1 Is there a way to paginate the results? i.e. ?page=1 or limit=10 Apr 27, 2018
@alex2118 alex2118 changed the title Is there a way to paginate the results? i.e. ?page=1 or limit=10 Is there a way to paginate the results? i.e. ?page=1 or ?limit=10 Apr 27, 2018
@ghost
Copy link

ghost commented May 4, 2018

Yes, a list of all the routes you can use is here: https://github.com/typicode/json-server

@singhBijendraIOS
Copy link

singhBijendraIOS commented May 13, 2019

Yes, this is easy . use this like

http://jsonplaceholder.typicode.com/photos?_start=0&_limit=5

@dotnetCarpenter
Copy link

I've documented pagination in PR #105 which should make it easier to spot this feature.

@sab-exp
Copy link

sab-exp commented Sep 9, 2019

Here's an example of the pagination made with JSON placeholder and Nuxtjs.
https://codesandbox.io/embed/pagination-browser-back-broken-6mu4r

@skipjack
Copy link

This doesn't seem to work as far as I can tell, I keep getting "Application Error" whenever I pass any query parameters.

@dotnetCarpenter
Copy link

dotnetCarpenter commented Apr 25, 2020

@skipjack please go to a site that does not have Content Security Policy (CSP) directive connect-src set to self and copy/paste the following into your console (ctrl+shift+i):

fetch('https://jsonplaceholder.typicode.com/posts?_page=1&_limit=2')
  .then(async response => {
    const link = response.headers.get('link') // link to next page (REST)
    const json = await response.json() // data payload
    console.log(link, json)
  })

What do you get back? If you get an array with 2 objects, then it works.

In the Speed Dial page in Opera (ctrl+t), I get the following output:

0: {userId: 1, id: 1, title: "sunt aut facere repellat provident occaecati excepturi optio reprehenderit", body: "quia et suscipit↵suscipit recusandae consequuntur …strum rerum est autem sunt rem eveniet architecto"}
1: {userId: 1, id: 2, title: "qui est esse", body: "est rerum tempore vitae↵sequi sint nihil reprehend…aperiam non debitis possimus qui neque nisi nulla"}
length: 2
__proto__: Array(0)

https://github.com/ has CSP connect-src, so you can not test it on this site.

@i-zakiro
Copy link

GET /posts?_page=7
GET /posts?_page=7&_limit=20

instruction : https://github.com/typicode/json-server/blob/master/README.md#paginate

@MattBevis
Copy link

would be nice to include the total number of pages in the response or am I missing something?

@lazarevic-00
Copy link

would be nice to include the total number of pages in the response or am I missing something?

I also needed the same thing, and it's there, it's inside response headers under key x-total-count.

fetch('https://jsonplaceholder.typicode.com/posts?_start=1&_limit=10')
  .then(response => {
    // Accessing the headers
    const headers = response.headers;

    const totalCount = headers.get('x-total-count') // total count of elements
    console.log(totalCount);
    return response.json();
  })
  .then(data => {
    console.log('Data:', data);
  })
  .catch(error => {
    console.error('Error:', error);
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants