Push & Webhooks
This is the official documentation of the @forestadmin/agent
Node.js agent.
Some APIs expose the capability of following changes.
This can take the form of webhooks, WebSockets, long polling, or any other mechanism.
When this is the case, you can use the "push" strategy to keep the replica up-to-date.
Programming your handler
Unlike with the "pull" strategy, you are responsible for setting up the subscriptions to the target API.
When the agent starts, it will call your handler to set up the subscriptions.
Then, each time a change is received, you are responsible for sending it to the agent so that the replica can be updated.
Examples
Example 1: With an API that provides a change feed
Some APIs conveniently provide a change feed that you can subscribe to using a WebSocket or a long polling mechanism.
Example 2: With an API that provides webhooks
Dealing with webhooks is a bit more complex than with a change feed, as you need to expose an HTTP server to receive the webhooks.
You may also want to share an HTTP server with the agent (using different URL prefixes), but this is out of the scope of this example, as it brings complexity that is not related to the replication strategy, and is out of the scope of this example.
Last updated