-1

This is in the context of a Python API. I have a column where the value can be either True, False or Null, lets call it is_impounded. The Null "value" is when it is unknown whether it is impounded or not.

I want to be able to pass a query parameter in a GET request which gets all rows where it is unknown whether the car is impounded. I cant pass GET /cars?is_impounded=None because that is the same as GET /cars which returns ALL rows. My other thought was to use the strings 'yes' 'no' 'unknown' as the column value and then query GET /cars?is_impounded=unknown. But that just seems a bit odd.

Has anyone had this issue before and how did you resolve it?

2
  • This is not a Python question as the answer depends entirely on the implementation details of the third-party API that you are passing GET requests to. You may be able to use /cars?is_impounded= or it may implement something else such as passing JSON /cars?filters={"is_impounded":null} or anything else. Commented Mar 14 at 12:55
  • If you are asking how other APIs implement this (which is probably too broad of a question) then you can look at Django which would pass a Q object to perform the filtering something like Cars.objects.all(Q(is_impounded__isnull=True)) Commented Mar 14 at 13:01

2 Answers 2

0

Try

GET /cars?is_impounded=null

instead of

GET /cars?is_impounded=None
Sign up to request clarification or add additional context in comments.

Comments

0

You have four possible states: all, true, false or unknown.

All you need is four possible filter values for your API endpoint:

  • GET /cars?is_impounded=*
    GET /cars?is_impounded=true
    GET /cars?is_impounded=false
    GET /cars?is_impounded=null
    

or

  • GET /cars?is_impounded=ALL
    GET /cars?is_impounded=IMPOUNDED
    GET /cars?is_impounded=NOT_IMPOUNDED
    GET /cars?is_impounded=UNKNOWN
    

or

  • GET /cars?is_impounded=
    GET /cars?is_impounded=YES
    GET /cars?is_impounded=NO
    GET /cars?is_impounded=UNDEFINED
    

or any other combination of values with the same semantic meaning.

What you chose is personal preference.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.