Skip to content
You are reading the HappyView v2 docs, which are no longer updated. Read the v3 docs.

Create Record

The simplest write: take the request body, save it as a record, and return the URI.

Lexicon type: procedure

function handle()
local r = Record(collection, input)
r:save()
return { uri = r._uri, cid = r._cid }
end
  1. Create a new Record instance from the target collection, populated with the fields from the request body.
  2. Call r:save(), which creates the record on the caller’s PDS and indexes it locally.
  3. Return the AT URI and CID of the newly created record.
const response = await fetch("http://127.0.0.1:3000/xrpc/xyz.statusphere.createRecord", {
method: "POST",
headers: {
"X-Client-Key": CLIENT_KEY,
Authorization: `Bearer ${TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
text: "Hello world",
createdAt: "2025-01-01T00:00:00Z",
}),
});
const data = await response.json();

This is the simplest possible write procedure. It works well when the client is responsible for populating all record fields and no server-side validation or transformation is needed.