I am trying to create a restful service using firebase as backend. I have created a sample app and when I hit this url [ https://poctest1.firebaseio.com/rest.json ], I am getting the following response.
"value": "test 2"
Why am I getting a null on top, I haven't inserted any.
Help me to figure this out. Thanks
Best How To :
What you're seeing is how Firebase's SDKs deserialize array-like structures. Firebase's documentation on arrays explains it:
when data is read using
val() or via the REST api, if the data looks like an array, Firebase will render it as an array. In particular, if all of the keys are integers, and more than half of the keys between 0 and the maximum key in the object have non-empty values, then Firebase will render it as an array.
Since your array doesn't have an element at index 0, Firebase injects a
null for that.
In general when using Firebase you should try to not use arrays, for the reasons mentioned in the documentation I linked above. If you find your must use an array, make sure that you always update the entire array in Firebase. So don't try to manipulate specific items in the array.