Best Practice of Doing API Call from Javascript

Hi there,

I have a small dilemma.

We are building an app that does almost the same as AirBNB search results (filter) page.

We are fetching all the properties via API and then on updating the map, we need to show properties within that section.

What is a general best practice for when having to make API calls to get a list of something, and then filter it on the frontend … ?

Do we always make API calls and have the API return the exact data to show (filtered) or we make the initial API call with all the properties and then work with that data on the frontend (calculating filters)?

Depends on how efficient it is, e.g. you don’t want to send 1000’s of records to the client if there’s only 20 displayed.

filtering on the client side is easy, so there’s no restriction there.

var specialData = data.filter(function(d) {
  return d.category == 'special';
});

In general you should paginate and filter server side. This solution scales and performs the best. We use Exact Target at work. Their GUI is a perfect example of how slow and poor performing doing it clients-side can become as the data set becomes larger. Sometimes the pages even just error out due to the data set size. 100 rows is a good number per page.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.