Reading Data

Read AT Protocol Records

Listing Records

You can read records from a user's data repository with client.list():

const posts = await client.list(app.bsky.feed.post, {
  limit: 10,
  repo: 'alex.bsky.team',
})

Each Lexicon will have its own parameters; for app.bsky.feed.post, you can specify the repo (a user's handle or DID) and a limit on the number of posts to return.

Refer to app.bsky.feed.post for this complete Lexicon.

Getting Records

You can use client.get() to read an individual record by its rkey:

const post = await client.get(app.bsky.feed.post, {
  rkey: '3jxf7z2k3q2',
})

DID Resolution

In AT, user data is resolved through DIDs, also known as Decentralized Identifiers. Most AT Protocol applications use did:plc DIDs when registering user accounts.

You can resolve a known username to a DID using the com.atproto.identity.resolveHandle endpoint. This means that you can just visit this address in a browser with a handle= arugment to look up your DID:

https://bsky.social/xrpc/com.atproto.identity.resolveHandle?handle=youraccount.bsky.social
{
did: "did:plc:3vekukmab2djjeengw2o3wln"
}

The Typescript SDK also provides the DID of the currently-authenticated as client.did:

const your_did = client.did

Unauthenticated Reads

Some API endpoints can be accessed without authentication. You can create an unauthenticated client by passing a public API URL to a new Client:

import { Client } from '@atproto/lex'
import * as app from './lexicons/app.js'

const client = new Client('https://public.api.bsky.app')

As with an authenticated client, you can .get() any public records, like a user's profile:

const profile = await client.get(app.bsky.actor.profile)

You can make API calls to any Lexicon using the same SDK client pattern. For more examples, refer to the SDK documentation.

Next, you might try writing to a user's data repository.

Further Reading and Resources