2 ms·
This 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 the
by compscistd 7y ago
This 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.