import { FeedsClient } from "@stream-io/feeds-react-sdk";
const client = new FeedsClient("<API key>");
await client.connectUser({ id: "john" }, "<user token>");
// Create a feed (or get its data if exists)
const feed = client.feed("user", "john");
// Subscribe to WebSocket events for state updates
await feed.getOrCreate({ watch: true });
// Add activity
await feed.addActivity({
text: "Hello, Stream Feeds!",
type: "post",
});Quick Start
Stream lets you build activity feeds at scale. The largest apps using Stream have over 100 Million users. Stream Activity Feeds scales effectively while giving you more flexibility over the content shown in your feed.
Getting Started
For SDK-accurate examples generated from the OpenAPI spec, use the Stream snippets reference: TypeScript SDK - Feeds API. Replace node in the URL with the SDK language you want to inspect.
use GetStream\ClientBuilder;
use GetStream\GeneratedModels;
$feedsClient = (new ClientBuilder())
->apiKey($apiKey)
->apiSecret($apiSecret)
->buildFeedsClient();
// Create a feed (or get its data if exists)
$feed = $feedsClient->feed("user", "john");
$feed->getOrCreateFeed(
new GeneratedModels\GetOrCreateFeedRequest(userID: "john")
);
// Add activity
$response = $feedsClient->addActivity(new GeneratedModels\AddActivityRequest(
type: 'post',
feeds: ['user:john'],
text: 'Hello, Stream Feeds!',
userID: 'john'
));Key Concepts
Activities
Activities are the core content units in Stream Feeds. They can represent posts, photos, videos, polls, and any custom content type you define.
Feeds
Feeds are collections of activities. They can be personal feeds, timeline feeds, notification feeds, or custom feeds for your specific use case.
Real-time Updates
Stream Feeds provides real-time updates through WebSocket connections, ensuring your app stays synchronized with the latest content.
Social Features
Built-in support for reactions, comments, bookmarks, and polls makes it easy to build engaging social experiences.
Server-side vs client-side
Most API calls can be made client-side. Client-side API calls use the permission system. Server-side API calls have full access.
Most apps will default to making API calls client-side. Engineers will often use server-side to do the following tasks:
- Updating feed groups or feed views for ranking and aggregation
- Syncing users
- Returning tokens for authenticating users
- Writing to feeds that do not belong to the current user (since the user does not have access client side to do this)
Common Use Cases
Social Media Feed
$feedsClient = (new ClientBuilder())
->apiKey($apiKey)
->apiSecret($apiSecret)
->buildFeedsClient();
// Create timeline feed
$timeline = $feedsClient->feed("timeline", "john");
$response = $timeline->getOrCreateFeed(
new GeneratedModels\GetOrCreateFeedRequest(userID: "john")
);
// Add a reaction to activity
$reactionResponse = $feedsClient->addActivityReaction(
"activity_123",
new GeneratedModels\AddReactionRequest(
type: "like",
userID: "john"
)
);
// Add a comment to activity
$commentResponse = $feedsClient->addComment(
new GeneratedModels\AddCommentRequest(
objectID: "activity_123",
objectType: 'activity',
comment: 'Great post!',
userID: 'john'
)
);
// Add a reaction to comment
$commentReactionResponse = $feedsClient->addCommentReaction(
$commentResponse->getData()->comment->id,
new GeneratedModels\AddCommentReactionRequest(
type: "love",
userID: "john"
)
);Notification Feed
// Create a notification feed
$notifications = $feedsClient->feed("notification", "john");
$notifications->getOrCreateFeed(
new GeneratedModels\GetOrCreateFeedRequest(userID: "john")
);
// Mark notifications as read
$markResponse = $notifications->markActivity(
new GeneratedModels\MarkActivityRequest(markAllRead: true, userID: "john")
);Polls
$feedsClient = (new ClientBuilder())
->apiKey($apiKey)
->apiSecret($apiSecret)
->buildFeedsClient();
$client = (new ClientBuilder())
->apiKey($apiKey)
->apiSecret($apiSecret)
->build();
// Create a poll
$poll = new GeneratedModels\CreatePollRequest(
name: 'What is your favorite color?',
userID: 'john',
options: [
new GeneratedModels\PollOptionInput("Red"),
new GeneratedModels\PollOptionInput("Blue"),
new GeneratedModels\PollOptionInput("Green"),
]
);
$pollResponse = $client->createPoll($poll);
$pollData = $pollResponse->getData();
$pollId = $pollData->poll->id;
// Create activity with the poll
$pollActivity = new GeneratedModels\AddActivityRequest(
type: 'poll',
feeds: ['user:john'],
pollID: $pollId,
text: 'What is your favorite color?',
userID: 'john'
);
$response = $feedsClient->addActivity($pollActivity);
// Vote on the poll
$activityData = $response->getData();
$activityId = $activityData->activity->id;
$optionId = $pollData->poll->options[0]->id;
$voteResponse = $feedsClient->castPollVote($activityId, $pollId,
new GeneratedModels\CastPollVoteRequest(
vote: new GeneratedModels\VoteData(optionID: $optionId),
userID: "john"
)
);Advanced Features
Custom Activity Types
Create custom activity types to represent your app's specific content:
// Create a feed (or get its data if exists)
$feed = $feedsClient->feed("user", "john");
$feed->getOrCreateFeed(
new GeneratedModels\GetOrCreateFeedRequest(userID: "john")
);
// Add custom activity
$feedsClient->addActivity(
new GeneratedModels\AddActivityRequest(
type: "workout",
text: "Just finished my run",
userID: "john",
feeds: ["user:john"],
custom: (object)[
"distance" => 5.2,
"duration" => 1800,
"calories" => 450,
],
)
);Real-time Updates with State Layer
Only for client-side SDKs
const feed = client.feed("user", "john");
// Subscribe to WebSocket events for state updates
await feed.getOrCreate({ watch: true });
// Read state reactively with hooks
const { activities } = useFeedActivities(feed) ?? {};