Cara menggunakan getstream nodejs example
Social media app can quickly go viral but at the same time it is tremendously difficult to get right. In today’s social media app market users expect your app to have certain features that are hard to implement. Building those features from scratch takes a long time. So in this post I’m showing how you can leverage Stream API to build your social media app components, make the development faster and save yourself weeks, if not months of work. Have a separate serverSince social media app is bound to be complicated, it’s always a good idea to have a separate back-end server for it. In this tutorial we’re going to use Node.JS and Stream’s JavaScript library to build our back end, but you can choose any language and platform that you wish. Stream has libraries for most of the popular server side frameworks like Java, Go, .NET, Ruby and etc. What is Stream?In short, Stream is an API for handling user interactions and activity streams in your social media app. Stream includes free and paid tiers. Paid tier is of course more powerful and feature-rich but their free tier can still help you immensely in building your app. What Stream is meant to be used as:
What Stream is not meant to be used as:
UsersUsers are the building block of any social media app so it’s important to take time to consider the architecture for your user data. However, Stream is not really built to store a whole lot of user data in it. I even suggest not to store any user data in Stream and use your own database for that instead. The only thing you really need to store in Stream is a unique user identifier to tie the users to their posts and reactions. Unique identifier can be anything you choose as long as it’s truly unique(email, username, user hash and etc). FeedsStream provides 3 types of feeds:
Don’t worry if the difference between the feeds is not very apparent. The main takeaway here is that different feeds are better suited for different purposes. Also, do not think that you can only choose one or the other. You can (and should) have more than one feed in your project, each handling different responsibility. ActivitiesActivity is a content item that forms your social media app’s data. Activities can be almost anything like posts or user events and etc. Each activity has three mandatory fields: ReactionsReaction is a special kind of data that captures user’s interaction with other people’s activities in your social media app. Reactions can be likes, comments, upvotes and etc. Also, reactions are always tied to the specific activity. When creating a reaction you need to provide
four fields: NotificationsThe last type of Stream data that I want to talk about is notifications. The way to create and manage notifications in Stream is by creating a separate Notification Feed. Adding a new notification is just like adding a new activity to the feed. You can also setup realtime notifications in your social media app by subscribing to feed updates via web-hooks or socket connections. Stream JavaScript library comes with the built-in support for realtime updates via sockets. ExamplesNow that we’re familiar with the building blocks of Stream API let’s take a look at some examples. Connecting to Stream API
As you can see, creating a new client instance is easy, all you need to do is provide key, secret and id of your project. You can get all three from your Stream Dashboard. Following people In my project I have 3 different feeds with different purposes:
In this example Getting feed activities
In this example we’re getting all the recent activities in user’s
Adding activity
In this example we’re adding a new post to user’s
Adding activity reactions
This method is for adding new reactions to the activities. First we instantiate a new client and use You can easily fetch reactions for the activity:
And that’s it for this post! You can definitely find more explanation and API examples by visiting Stream documentation . Building a social media app is no easy feat, but with the help of Stream API that daunting task seems much more manageable. If you’d like to get more web development, React and TypeScript tips consider following me on
Twitter, where I share things as I learn them. |