Skip to content

Commit

Permalink
Merge pull request thisbejim#109 from shamrin/patch-1
Browse files Browse the repository at this point in the history
Better streaming docs
  • Loading branch information
thisbejim committed Nov 28, 2016
2 parents 042f55b + c98adc8 commit 0d6b279
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,18 @@ Note: ```shallow()``` can not be used in conjunction with any complex queries.
You can listen to live changes to your data with the ```stream()``` method.

```python
def stream_handler(post):
print(post["event"]) # put
print(post["path"]) # /-K7yGTTEp7O549EzTYtI
print(post["data"]) # {'title': 'Pyrebase', "body": "etc..."}
def stream_handler(message):
print(message["event"]) # put
print(message["path"]) # /-K7yGTTEp7O549EzTYtI
print(message["data"]) # {'title': 'Pyrebase', "body": "etc..."}

my_stream = db.child("posts").stream(stream_handler)
```

You should at least handle `put` and `patch` events. Refer to ["Streaming from the REST API"][streaming] for details.

[streaming]: https://firebase.google.com/docs/reference/rest/database/#section-streaming

You can also add a ```stream_id``` to help you identify a stream if you have multiple running:

```
Expand Down

0 comments on commit 0d6b279

Please sign in to comment.