Skip to main content
This example illustrates using a Server-Sent Event (SSE) connection to receive data. The advantage of using an SSE is that you do not have to write a polling loop to check for new data.

Creating a Granta Integration Service session

The first part of this script (creating a session) is the same as in the Getting Started example:

Opening an SSE connection

Next we add the code to connect via SSE:
This connection will stay open indefinitely, and you can receive data on this connection as soon as it is available. To demonstrate receiving data from the SSE connection, add:
This waits for events that have data and provides the information. In this example we wait for 3 events. An event will fire when you click “Fetch material data” in the Granta Material Picker.

Ending the session

To close the session down and ensure no more materials can be received, send an HTTP DELETE request to the session URL: