4 ms·
The person you replied to doesn't like returning "null". He/she would probably prefer returning an array that contains 0 items.
by chihuahua 7y ago
The person you replied to doesn't like returning "null". He/she would probably prefer returning an array that contains 0 items.
- compscistd 7y agoThis makes sense now. If I did a GET to posts and got a "null", I would think I made some kind of error. If I get an empty array, I would (correctly) assume there are no posts yet. Basically, GET to posts would always return an array of posts. Whether there are 0 (empty array), 1 (just one object in the array), or many (array with n length). This makes API logic way easier to handle without having to check what structure I received even with a 200 status code
- WrtCdEvrydy 7y agoAlso makes a lot of iteration easier... just a for loop over the array to dump something on the page with no edge cases. You can add a warning by just checking the length against that array blindly.
- jandrese 7y agoHe called it a "null array" which I interpret as an array containing zero items. If it was just a plain old null then yeah, that's super annoying.