Script Examples
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 }
endHow it works
- Create a new
Recordinstance from the target collection, populated with the fields from the request body. - Call
r:save(), which creates the record on the caller's PDS and indexes it locally. - Return the AT URI and CID of the newly created record.
Usage
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();Use case
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.