computingfacts / openhouse

The Food Culture
Apache License 2.0
0 stars 0 forks source link

Pagination #13

Open Nicholas-Robinson opened 7 years ago

Nicholas-Robinson commented 7 years ago

I am a little confused with the pagination stuff - I assume that "number" is the page number and "totalPages" is the total number that there will be.

I am confused because number starts at 0 and ends at totalPages - 1, I also cannot request page 0 (even though the 500 error says that index cannot be less than zero).

I am trying to request the next page and I was using load page number + 1 .. But this was just loading the same page every time.

computingfacts commented 7 years ago

There are two endpoints for recipes with pagination.

  1. http://www.computingfacts.com/openhouse/api/recipe/recipes/pageable

For the above endpoint, default for first page =0 and size =10, try this

curl -X GET --header 'Accept: application/hal+json' --header 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJibGFja25pdGVlIiwiaWF0IjoxNTAyNDkwNjc2LCJleHAiOjE1MzQwMjY2NzZ9.oyvcPaT1Thnqs5wuwZ3HXPMUgJYHr00koHObQIkz41R0TXQsrPvBJnwie6QJFcyH_Rzv7dIlEqRhcZ8kJVhCqQ' 'http://www.computingfacts.com/openhouse/api/recipe/recipes/pageable?page=0&size=10'

To get the second page try this

curl -X GET --header 'Accept: application/hal+json' --header 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJibGFja25pdGVlIiwiaWF0IjoxNTAyNDkwNjc2LCJleHAiOjE1MzQwMjY2NzZ9.oyvcPaT1Thnqs5wuwZ3HXPMUgJYHr00koHObQIkz41R0TXQsrPvBJnwie6QJFcyH_Rzv7dIlEqRhcZ8kJVhCqQ' 'http://www.computingfacts.com/openhouse/api/recipe/recipes/pageable?page=1&size=10'

Below is the result which shows the second page, in this case just one result.

{code} ~ joseph$ curl -X GET --header 'Accept: application/hal+json' --header 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJibGFja25dGVlIiwiaWF0IjoxNTAyNDkwNjc2LCJleHAiOjE1MzQwMjY2NzZ9.oyvcPaT1Thnqs5wuwZ3HXPMUgJYHr00koHObQIkz41R0TXQsrPvBJnwie6QJFcyH_Rzv7dIlEqRhcZ8kJVhCqQ' 'http://www.computingfacts.com/openhouse/api/recipe/recipes/pageable?page=1&size=10' { "_embedded" : { "recipeViews" : [ { "recipeId" : 11, "recipeName" : "456", "recipeDescription" : "654", "recipePrepTime" : "1970-01-01T00:00:45.000+0000", "recipeCookTime" : "1970-01-01T00:00:00.000+0000", "recipeCreationDate" : { "year" : 2017, "month" : "AUGUST", "monthValue" : 8, "dayOfMonth" : 18, "hour" : 23, "minute" : 1, "second" : 6, "nano" : 0, "dayOfWeek" : "FRIDAY", "dayOfYear" : 230, "chronology" : { "calendarType" : "iso8601", "id" : "ISO" } }, "recipeModificationDate" : null, "recipeYield" : "654", "recipeImageUrl" : "https://static.pexels.com/photos/2232/vegetables-italian-pizza-restaurant.jpg", "recipeAuthor" : { "userId" : 1, "emailAddress" : "blacknitee@yahoo.com", "username" : "blacknitee", "firstName" : "Joe", "lastName" : "Sampson", "fullName" : "Joe Sampson", "avatarHash" : "26eb8959643a9e1567c2379b9b38bd5e", "isActive" : true, "profileImageUrl" : null, "profileType" : "website" } } ] }, "_links" : { "first" : { "href" : "http://www.computingfacts.com/openhouse/api/recipe/recipes/pageable?page=0&size=10" }, "prev" : { "href" : "http://www.computingfacts.com/openhouse/api/recipe/recipes/pageable?page=0&size=10" }, "self" : { "href" : "http://www.computingfacts.com/openhouse/api/recipe/recipes/pageable?page=1&size=10" }, "last" : { "href" : "http://www.computingfacts.com/openhouse/api/recipe/recipes/pageable?page=1&size=10" } }, "page" : { "size" : 10, "totalElements" : 11, "totalPages" : 2, "number" : 1 } {code}

Notice, this links, that could be used to request for prev, next or current page

computingfacts commented 7 years ago
  1. http://www.computingfacts.com/openhouse/api/recipe/recipes?page=2&pagesize=10 note: if not page , defaults page =1, if no pagesize, defaults pagesize =10 For the second endpoint, Note the start page is not 0 rather 1. so to request for the second page, try this

curl -X GET --header 'Accept: application/json' --header 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJibGFja25pdGVlIiwiaWF0IjoxNTAyNDkwNjc2LCJleHAiOjE1MzQwMjY2NzZ9.oyvcPaT1Thnqs5wuwZ3HXPMUgJYHr00koHObQIkz41R0TXQsrPvBJnwie6QJFcyH_Rzv7dIlEqRhcZ8kJVhCqQ' 'http://www.computingfacts.com/openhouse/api/recipe/recipes?page=2&pagesize=10'