Api Design: Which is Better: Returning Null for Null Values ​​or Nothing

I am developing my first API for a MongoDB data warehouse web application. I am returning json answers and I don't know how to decide which is better:

Saving a consistent response pattern with empty fields or zeros. Or return only non-empty values.

This means that when deleting values ​​from an array on my Mongo, I need to check if the array is empty, and if so, then $ unset it.

+4
source share
1 answer

I prefer to avoid zeros for relational schemas and application code; I would recommend the same for NoSQL.

"null" means "I don't know" for me.

An empty object says: "You asked for it, but there was nothing." I think this is more explicit and correct.

+11
source

Source: https://habr.com/ru/post/1385806/


All Articles