Skip to content

Create a record

The simplest write: save the request body as a record and return its URI.

Trigger: xrpc.procedure:<nsid>. Needs: happyview-record.

local record = require("happyview.record")
function handle(input, ctx)
return record.create(ctx.collection, input)
end
import record from "happyview.record";
export default function handle(input, ctx) {
return record.create(ctx.collection, input);
}
import record from "happyview.record";
export default function handle(input: Record<string, unknown>, ctx: { collection: string }) {
return record.create(ctx.collection, input);
}
  1. record.create writes the record to the caller’s PDS in the lexicon’s target collection.
  2. The write is also put into HappyView’s index straight away, without waiting for the network to echo it.
  3. create returns { uri, cid }, which becomes the response.

Writing as the caller needs a PDS session, which a procedure has when its caller is signed in. Check ctx.has_pds_auth if you need to handle the case where it isn’t.

Terminal window
curl -X POST http://127.0.0.1:3000/xrpc/xyz.statusphere.createRecord \
-H "X-Client-Key: $CLIENT_KEY" \
-H "Authorization: DPoP $ACCESS_TOKEN" \
-H "DPoP: $DPOP_PROOF" \
-H "Content-Type: application/json" \
-d '{ "text": "Hello world", "createdAt": "2025-01-01T00:00:00Z" }'