How do changes REST API feed options work?


#1

I am trying to write an NodeJS agent for Sync Gateway that listens for changes, but I don’t understand how to use the feed options: normal, continuous, longpoll, websocket.

I get how I could use a timer and the normal option and do a polling, but don’t see how the other options work. Does anyone have a good example or even just a more complete description of how continuous, longpoll, or websocket works?


#2

hey @sweetiewill can you help out here please


#3

Hey @chrismbeckett,

The timer with normal option works and can look into examples on the topic but regarding a more complete description of the feed options:

normal: Immediately the ‘_changes’ endpoint will return with the results
longpoll: Server will have the client HTTP request stay open for a duration and have new results returned to the client.
continuous: This is similar to the ‘longpoll’ feed option but in that the socket is remained opened and never closed.

Curious what are you using the NodeJS agent for other than listening for changes.


#4

I am implementing dynamic permissions into my application. I have a group document that needs to become an actual sync gateway role. I added a provisioning property to my group document, and I need a server side agent to watch for group documents, and then create the role on the admin REST API when a new group document is created.

I found this explanation of longpoll and continuous this morning (http://guide.couchdb.org/draft/notifications.html). It basically says don’t use longpoll, but I was thinking that for a server-side agent continuous or websocket might be the best choice, but am concerned about issues with the connection closing etc.

Is normal with a timer and polling just the best practical/recommended option? Seems the most straight-forward and least likely to break in production.


#5

It sounds like a good use case for using a webhook (released in Sync Gateway 1.1).
You can find examples of how to use webhooks in this blog post and roles in this guide.

James


#6

Hey @jamiltz, thanks for this suggestion and the links. Web hooks look great and seem a much better solution than polling.