Do you know how to setup Firestore listening using REST API. This is my attempt:
url: "https://firestore.googleapis.com/v1beta1/projects/project_name/databases/(default)/documents:listen"
headers: {["Content-Type"] = "application/json"}
body: "{"addTarget": {
"once" : false,
"documents" : {
"documents" : [ "projects/project_name/databases/(default)/documents/Users/USER_DOC_ID" ]
}
}}"
Request verb: POST
And the response:
[{
"error": {
"code": 400,
"message": "Invalid value (Object), ",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid value (Object), "
}
]
}
]
}
}
]
Most propably, my request body is invalid. I used this reference: https://firebase.google.com/docs/reference/rest/firestore/v1beta1/projects.databases/listen
How is the body should look like? Thanks in advance.
You can listen to a document with the onSnapshot() method. An initial call using the callback you provide creates a document snapshot immediately with the current contents of the single document. Then, each time the contents change, another call updates the document snapshot.
If you have a very time-sensitive app, like online auctions where you can't have unpredictable delays (no one likes to lose because of something that we don't control), you shouldn't really use Firestore. You will have a hard time hiding the hiccups and you will only anger your users.
We can use any Firebase Realtime Database URL as a REST endpoint. All we need to do is append . json to the end of the URL and send a request from our favorite HTTPS client.
The listen method is not available through the REST API. It is available through the RPC API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With