Build a Social Platform

Communities, feeds, messaging, and profiles with the SDK

Set up communities, content feeds, messaging, and user profiles with the SDK.

Prerequisites

  • Node.js >= 18
  • A Recursiv API key with scopes: posts:read, posts:write, communities:read, communities:write, chat:read, chat:write, tags:read, tags:write

Install

$npm install @recursiv/sdk

Set up environment

$export RECURSIV_API_KEY=sk_live_xxx

The code

1import { Recursiv } from '@recursiv/sdk'
2
3const r = new Recursiv()
4
5async function main() {
6 // 1. Get your profile
7 const { data: me } = await r.profiles.me()
8 console.log('Logged in as:', me.username)
9
10 // 2. Create a community
11 const { data: community } = await r.communities.create({
12 name: 'Ship It',
13 slug: 'ship-it',
14 privacy: 'public',
15 })
16 console.log('Community:', community.id)
17
18 // 3. Create tags for content organization
19 const { data: tag } = await r.tags.create({ name: 'launch' })
20
21 // 4. Post to the community
22 const { data: post } = await r.posts.create({
23 content: '# We shipped!\n\nOur new feature is live. Check it out.',
24 content_format: 'markdown',
25 community_id: community.id,
26 tag_ids: [tag.id],
27 })
28 console.log('Post:', post.id)
29
30 // 5. React to the post
31 await r.posts.react(post.id, { type: 'fire' })
32
33 // 6. Search posts
34 const { data: results } = await r.posts.search({
35 query: 'shipped',
36 community_id: community.id,
37 })
38 console.log('Found', results.length, 'posts')
39
40 // 7. Start a DM
41 const { data: dm } = await r.chat.dm({ user_id: 'user_xxx' })
42 await r.chat.send({ conversation_id: dm.id, content: 'Hey! Check out the new post.' })
43
44 // 8. Create a group chat
45 const { data: group } = await r.chat.createGroup({
46 name: 'Launch Team',
47 member_ids: ['user_1', 'user_2'],
48 })
49 await r.chat.send({ conversation_id: group.id, content: 'We are live!' })
50
51 // 9. Follow another user
52 await r.profiles.follow('user_xxx')
53
54 // 10. List posts with tag filtering
55 const { data: tagged } = await r.posts.list({
56 tag_id: tag.id,
57 limit: 20,
58 })
59 console.log('Tagged posts:', tagged.length)
60}
61
62main()

What just happened

You built the core loop of a social platform:

  • A community with public membership
  • Content with markdown, tags, and reactions
  • Direct messaging and group chat
  • Social graph (follow/unfollow)
  • Content search and tag filtering

Next steps

  • Add auth with r.auth.signUp() / r.auth.signIn()
  • Update posts with r.posts.update(id, { content, tag_ids })
  • Manage unread counts with r.chat.unreadCount(conversationId)
  • Build a leaderboard with r.profiles.leaderboard()