Home > Enterprise >  API REST - filter ressources with a non null property - Guidelines?
API REST - filter ressources with a non null property - Guidelines?

Time:07-06

I have a question regarding the best guidelines when a consumer want to request a list of ressources from an API.

This is a simple schema of the ressource.

{
   "id" : "1234-5678-9123-465",
   "date": "2021-02-19T09:57:29.912Z"
}

Sometimes, the "date" value can be null.

The consumer wants to recover the ressources with a non null value.

To date, we use a parameter while requesting which is "min_date". We pass a value like "1970-01-01T00:00:00.000Z" and so we have all the ressources with a non null value.

GET /ressources?min_date=1970-01-01T00:00:00.000Z

Is it a good way to do it ? What will the best way in REST to request the ressources that has non null values in a specific property ?

I did not find another thread about this.

Thanks a bunch.

CodePudding user response:

I don't think it is a good way. Proper ways could be that

  1. You pass a flag param GET /ressources?nonNullFlag=true and the actual implementation of how you filter null values is internal server's business. This way you protect yourseld from invalid date parameter.
  2. Have a separate end point GET /ressources/notNull in addition to your original one but without a parameter
  • Related