Web applications often have tables of data, whether it’s the list of items for sale on Amazon, or notes in Evernote, and so on. Usually, users of the application are going to want to filter the results or sort through that data in some way.

If the dataset is pretty small, maybe a few hundred results, the API can return all the data at once and the front end will handle all the filtering, and no more API calls are required. Most of the time, however, the data could consist of tens of thousands to millions of rows, and it’s better to just get the data you need from smaller API calls as opposed to trying to request a million results every time the page loads.

Recently, I made a backend API for some list endpoints, and implemented filtering, sorting, and pagination. There’s not really a set standard for creating these types of endpoints, and almost every one I’ve come across is different in some way. I made a few notes on what made sense to me, so this resource could be helpful for someone who is working on designing an API.

Goals

In this article I’ll make an example API endpoint and SQL query for various sort, paginate, and filter APIs, with users as the table for all examples.

#rest api #api

REST API: Sorting, Filtering, and Pagination
78.45 GEEK