If there is no value in the response parameter of the REST API, which should I choose, null or empty?

Asked 2 years ago, Updated 2 years ago, 79 views

I'm developing a backend API and some response parameters do not have a value (such as null on DB) and I'm struggling with the design whether to return it as null or empty to match the type.

Currently, it is not unified, so the caller decides and absorbs it, but which one is better suited to?

api

2022-09-30 19:34

1 Answers

It's more of an opinion than an answer.

  • If you are preparing for an empty string to be "possible data", you should unify it to null or 0 if the data does not exist or has no meaning.
  • Currently, if there is no empty string, I think it would be a reality to prioritize the unification and decide on the one with the smaller amount of correction.


2022-09-30 19:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.