Tech & Engineering
6
min of reading
August 4, 2020

Good practices: Pagination and filters

Luciana Bandeira
Developer Experience
I help developers with onboarding and API best practices to ensure the best Developer Experience. In my spare time I dedicate myself to books, researching (and tasting) desserts and I'm passionate about travelling.
More about the author

Continuing with another post on good practices in API use, today we will talk about pagination. In case you've missed any of the other posts, here they are: HTTP Status and APIs and their methods

API Pagination

Whenever there is a need to return more details about any of the desired resource attributes, the pagination parameter can be used.

This use is necessary to avoid that the query executed in the API becomes overloaded, causing timeout when using the given request. In general, for all services that return large amounts of data, one should always use pagination to return the records.

Along with the pagination, it will be necessary to indicate the amount of information to be returned on each page. Therefore, it is recommended to use the size parameter and that this value is less than 200, depending on the type of query and information to be returned otherwise.

The use of this information together with the executed query makes the request for reading and backend return faster, thus causing a more pleasant and agile experience for the developer who is consuming the API.

That is, it improves the user experience and avoids a very extensive information processing, which can cause failure and even interruption of the reading (causing timeout, where the backend does not return the information in the required time).

In practice, an example of how to insert this information into the endpoint is through page=0&size=100.

Keep in mind that these parameter field names may change according to the implementation of your AP (you can find these fields as Page and Size; Offset and Limit; Page and PageSize; among others).

Using filters

Another great support in optimizing information queries is the use of filters.

Providing this use within its implementation is also of great help when it comes to a better experience of using APIs.

Through this feature, it will be possible for the developer to limit the information he wants to have returned, optimizing the requests executed for specifically what is needed.

Assuming that, in the request, you only want the return of the information that is with the status approved, you can insert in your request the filter status=approved (always remembering that these nomenclatures will depend on the implementation of your API), thus delimiting the returns only for this scenario.

So, are you now ready and aware of all the right recommendations and methods to make the best use of APIs?!

Paginação das APIs
subscribe to our newsletter with exclusive content.

Click and join the Sensedia News!

Click and join the Sensedia News!

Click and join the Sensedia News!

Thanks for reading!