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)endJavaScript
Section titled “JavaScript”import record from "happyview.record";
export default function handle(input, ctx) { return record.create(ctx.collection, input);}TypeScript
Section titled “TypeScript”import record from "happyview.record";
export default function handle(input: Record<string, unknown>, ctx: { collection: string }) { return record.create(ctx.collection, input);}How it works
Section titled “How it works”record.createwrites the record to the caller’s PDS in the lexicon’s target collection.- The write is also put into HappyView’s index straight away, without waiting for the network to echo it.
createreturns{ 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.
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" }'
