1

I am trying to use firebase database as my rest api and I am POSTed data in the following way

https://doctorapp-b8180.firebaseio.com/app.json

POST body

{"name":"facebook"}

It is very simple, it has one node called app that has child called name.

But when I POST what is happening is that its adding some sort of key. which looks like this.

KjIoN-2vKwHFHwwKf9y

Now, I need to do GET request and I need app with name facebook, but I cannot get that element because of the key POST request added. This is my GET request

https://doctorapp-b8180.firebaseio.com/app/facebook/name.json

This is returning null. But when I add the key like the following, its working

https://doctorapp-b8180.firebaseio.com/app/KjIoN-2vKwHFHwwKf9y/facebook/name.json

the thing is I want to GET data with name parameter not without key. Is it possible. Besides when I add an element I do not know it's key.

1 Answer 1

2

That's a push key. You'll have to query for the data you want.

Take a look at this documentation

Unable to test this, but try a query like this:

https://doctorapp-b8180.firebaseio.com/app.json?orderBy="name"&startAt="facebook"&endAt="facebook"

Make a note of this from the docs (emphasis mine):

Add Indexing to your Firebase Realtime Database Rules: If you're using orderBy in your app, you need to define the keys you will be indexing on via the .indexOn rule in your Firebase Realtime Database Rules. Read the documentation on the .indexOn rule for more information.

So you'll need to configure a rule for that.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.