0

Supposedly, My API retrieves JSON having around 100 ids and its respective values.

How do i limit it to first 10 ids with its values?

Is there any JAVA code to limit this?

[ { "id": 1, "name": "Leanne Graham", "username": "Bret", "email": "Sincere@april.biz", "address": { "street": "Kulas Light", "suite": "Apt. 556", "city": "Gwenborough", "zipcode": "92998-3874", "geo": { "lat": "-37.3159", "lng": "81.1496" } }, "phone": "1-770-736-8031 x56442", "website": "hildegard.org", "company": { "name": "Romaguera-Crona", "catchPhrase": "Multi-layered client-server neural-net", "bs": "harness real-time e-markets" } },

{ "id": 2, "name": "Ervin Howell", "username": "Antonette", "email": "Shanna@melissa.tv", "address": { "street": "Victor Plains", "suite": "Suite 879", "city": "Wisokyburgh", "zipcode": "90566-7771", "geo": { "lat": "-43.9509", "lng": "-34.4618" } }, "phone": "010-692-6593 x09125", "website": "anastasia.net", "company": { "name": "Deckow-Crist", "catchPhrase": "Proactive didactic contingency", "bs": "synergize scalable supply-chains" } },

..... "id":100, ...

Sam
  • 1
  • 1
  • 1
    Check if the server provides a way, like passing `limit=10` or such in the URL. If not, just stop reading after 10 JSON objects. – Robert Aug 09 '20 at 16:26

2 Answers2

1

Pagination is your best bet for this. So you could pass in some query params to the API call like limit and pageNumber. For example, GET /users?limit=10&page=1 will get you the first 10. If you are using Spring and a database on the backend. Spring Data JPA has pagination built in and it's fairly easy to use.

Steven Diamante
  • 207
  • 2
  • 7
0

You can use pagination to apply for the limit and page number. You can make a fetch request like => fetch(${url}/_limit=10&_page=1) and this will fetch you your desired output

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 21 '23 at 12:13