Getting Started

Getting Started in 5 steps

1 – Get your App Token

Signup on streamdata.io Portal.
Select default app or create a new one and get your AppToken under Settings > Security.

app-token-masked

2 – Install streamdata.io

<script src="/js/streamdataio.min.js?x69489"></script>

3 – Connect to your API through streamdata.io

var myEventSource = streamdataio.createEventSource("http://mysite.com/myJsonRestService?X-Sd-Token=[YOURTOKEN]");

4 – React to new data

Register your callbacks and update your UI when receiving data.

myEventSource.onData(function(data){
     // initialize your data with the initial snapshot    
}).onPatch(function(data){         
     // update the data with the provided patch
});

2 – Install streamdata.io

Inlcude the following dependencies in your project:

3 – Connect to your API through streamdata.io

String streamdataPrefix = "https://streamdata.motwin.net/";
String myApi = "http://mysite.com/myJsonRestService";
Map<String, String> header = new HashMap<String, String>();
header.put("X-Sd-Token", sdToken);
eventSource = new EventSource(new URI(streamdataPrefix), new URI(myApi), this, header);
eventSource.connect();

4 – React to new data

@Override
public void onMessage(String event, MessageEvent message) throws IOException {
    if ("data".equals(event)) {
        // initialize your data with the initial snapshot
    } else if ("patch".equals(event)) {
        // update data with patch
    } 
}

2 – Install streamdata.io

Inlcude the following dependencies in your project:

3 – Connect to your API through streamdata.io

// Initialize the TRVSEventSource event source with URL string
URL = [NSURL URLWithString:"https://streamdata.motwin.net/http://mysite.com/myJsonRestService?X-Sd-Token=[YOURTOKEN]"];
eventSource = [[TRVSEventSource alloc] initWithURL:URL];
eventSource.delegate = self;

// Open the event source
[eventSource open];

4 – React to new data

- (void)eventSource:(TRVSEventSource *)eventSource didReceiveEvent:(TRVSServerSentEvent *)anEvent
{
  if([anEvent.event isEqualToString:@"data"]==TRUE) 
  {
      // initialize your data with the initial snapshot
  } else if ([anEvent.event isEqualToString:@"patch"]==TRUE) 
  {
      // update data with patch
  }
}

5 – Start receiving data in realtime

Streamdata.io will start polling your API and will send you realtime updates only when new data is available. You have created a streaming API to feed your real-time animated UI.

One step further

Need some code sample to get started? Check this out!
HTTP Status Quiz – Javascript/D3.js
Github commits – Android
NewYork Times news feed – iOS
More in our blog section (JQuery, Riot.js, …)