Getting Started

Learn How Easy It Can Be To Build Scalable Newsfeeds and Activity Streams

Stream has official clients for JS/Node, Ruby, Python, PHP, Go, and Java. There are framework integrations available for Rails, Django, Laravel, Doctrine, Zend, and Node. In addition to the official clients, the community has built clients for.NET and Scala.

Setup

Let’s get set up! First, install the client as specified below:

// install via pub
 dart pub add stream_feed

All source code can be found on GitHub.

To instantiate the client you need an API key and secret. You can find the key and secret on the dashboard. The examples below already include your key and secret.

import 'package:stream_feed/stream_feed.dart';

// instantiate a new client (server side)
final client = StreamFeedClient.connect('{{ api_key }}', secret: '{{ api_secret }}');

If you want to use Stream on your mobile or web application, you need to generate a token server-side that the JS/Swift/Java client can use to authenticate as a user of your application.

Generate User Token Server-Side

This code generates the token for one of your users; a common place to do this is at signup or login. The token is then passed to the frontend.

final userToken = client.frontendToken("the-user-id");

Use Stream API client-side (JS, Swift)

import 'package:stream_feed/stream_feed.dart';
final client = StreamClient.connect('{{ api_key }}', token: '{{ feed_token }}', appId: '{{ app_id }}');

More details about authentication can be found in the REST docs

Quick Start

The quick start below shows you how to build a scalable social network. It highlights the most common API calls:

final chris = client.flatFeed('user', 'chris');

// Add an Activity; message is a custom field - tip: you can add unlimited custom fields!
 await chris.addActivity(Activity(
   actor: 'chris',
   verb: 'add',
   object: 'picture:10',
   foreignId: 'picture:10',
   extraData: {'message': 'Beautiful bird!'}));

// Create a following relationship between Jack's "timeline" feed and Chris' "user" feed:
 final jack = client.flatFeed('timeline', 'jack');
 await jack.follow(chris);

// Read Jack's timeline and Chris' post appears in the feed:
final results = await jack.getActivities(limit: 10);

// Remove an Activity by referencing it's Foreign Id:
await chris.removeActivityByForeignId('picture:10');

That was a good deal of information at once. The getting started docs provide a more detailed and interactive explanation.

© Getstream.io, Inc. All Rights Reserved.