1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//! read one record from a PDS: com.atproto.repo.getRecord (unauthenticated).
//!
//! run: zig build example-read-a-record
const std = @import("std");
const zat = @import("zat");
pub fn main(init: std.process.Init) !void {
const io = init.io;
const allocator = init.gpa;
const did = "did:plc:z72i7hdynmk6r22z27h6tvur"; // bsky.app
// find the account's PDS (see the "resolve an identity" recipe for this chain)
var did_resolver = zat.DidResolver.init(io, allocator);
defer did_resolver.deinit();
var doc = try did_resolver.resolve(zat.Did.parse(did).?);
defer doc.deinit();
const endpoint = doc.pdsEndpoint() orelse return error.NoPdsEndpoint;
// read one record by (repo, collection, rkey) — a plain GET, no auth needed
var client = zat.XrpcClient.init(io, allocator, endpoint);
defer client.deinit();
var params = std.StringHashMap([]const u8).init(allocator);
defer params.deinit();
try params.put("repo", did);
try params.put("collection", "app.bsky.actor.profile");
try params.put("rkey", "self");
const method = zat.Nsid.parse("com.atproto.repo.getRecord").?;
var resp = try client.query(method, params);
defer resp.deinit();
// the record is JSON; zat.json pulls fields by dotted path
var parsed = try resp.json();
defer parsed.deinit();
const record = parsed.value;
const name = zat.json.getString(record, "value.displayName") orelse "(none)";
const desc = zat.json.getString(record, "value.description") orelse "(none)";
std.debug.print("displayName: {s}\n", .{name});
std.debug.print("description: {s}\n", .{desc});
}