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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# read a record
fetch one record from a PDS with `com.atproto.repo.getRecord` — a plain, unauthenticated GET.
```zig
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});
}
```
```
displayName: Bluesky
description: official Bluesky account (check username👆)
...
```
This is `examples/03_read_a_record.zig` verbatim — copy it and `zig build example-read-a-record`.
A record is just JSON addressed by `(repo, collection, rkey)`. The collection
NSID (`app.bsky.actor.profile`) is defined by whichever app owns that lexicon —
the PDS only stores and serves it, it doesn't interpret it.
This GET trusts the PDS to hand back the record faithfully — fine for reading, but the bytes aren't self-authenticating on their own. Checking a record against the repo's signed commit is what the "walk a repo" recipe sets up.
**See also:** the [`getRecord`](https://docs.bsky.app/docs/api/com-atproto-repo-get-record) lexicon and the [repository](https://atproto.com/specs/repository) spec. Record browsers and appviews are built on reads like this.
<details>
<summary>wiring zat into your own <code>build.zig</code></summary>
```zig
const zat = b.dependency("zat", .{}).module("zat");
exe.root_module.addImport("zat", zat);
```
after `zig fetch --save https://tangled.org/zat.dev/zat/archive/main`.
</details>