Sarah Sarah - 1 year ago 255
reST (reStructuredText) Question

How can I check if a key exists in my db using Firebase REST API?

I am using the Firebase REST API. I would like to check to see if a key exists in my database before writing to it. If it does not exist, I want to create it and write a set of default data to that key. If it does exist, I want to update the data at that key.

Right now I am attempting this by sending a GET request for that key, as in this example:

curl ''

and checking the response data. However, while the response data is empty if the key does not exist, it also appears to be empty if there was any other type of error retrieving the data.

Is there another way to check if a key exists using the REST API, like a URI parameter I can use? If not, is there a way to tell if the response data is empty because the key does not exist, or because there was an error?

Answer Source

The REST API will return a 200 status code and a body of null when the location is empty. Other errors will return a 4xx or 5xx status code.

curl -I

HTTP1/1 200 OK
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download