Paging, sorting, filtering and retrieving specific fields in your RESTful API

Paging your results: use limit & offset query parameters, return x-total-count header

  1. Return the total number of results via an X-Total-Count header
  2. If you want to provide links to previous and next pages, you can use the Link HTTP header
  3. In your implementation, set a maximum limit, such as 1000, to avoid server issues

Sorting your results: use sort query parameter

Filtering your results: use query parameters

Searching your results: use a q query parameter

Retrieving specific fields: use a fields query parameter

Advanced filtering: use LHS brackets

  1. Using LHS brackets with an operator: price[lte]=200 status[ne]=past
  2. Using RHS colon with an operator: price=lte:200 status=ne:past
  3. Using Lucene syntax or ElasticSearch Simple Query strings directly: q=price:<200 q=-status:past
  • Easy to use for your users
  • Relatively simple to parse server side
  • Relatively intuitive
  • Easy to parse server side
  • Easy to use for your users
  • No possibility to do an OR for combined filters
  • Less intuitive than LHS brackets
  • The most flexible of all
  • Almost no parsing required server-side (can be handed over directly to ElasticSearch for example)
  • Steep learning curve for your users
  • Requires URL percent encoding (makes it harder to use from curl or postman)

--

--

--

Développeur web et passionné de finances personnelles

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Girvan Newman Changing the Times

[edX SDS Micromasters] 6.86x Machine Learning with Python-From Linear Models to Deep Learning

How to deploy your Dash app on the IIS windows server

Behind the scenes of K8s

Unit Testing with Visual Studio 2017

Community point product kitchen great.

Power BI: Creating Date Table with DAX

Transform your stupid models to models to please your business owners

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Guillaume Viguier-Just

Guillaume Viguier-Just

Développeur web et passionné de finances personnelles

More from Medium

The SOLID Principles

What is JWT. How to implement JWT based authentication in NodeJs?

How to implement JWT based authentication in NodeJs

Hands-on with Atomic Commits — Part 2: The Project

Versioning Best Practices for API Architecture