Data
Keep records in collections and reach them with an API: a static site can collect sign-ups without server code, and a server app can read and write with its secret key.
On this page
How it works
Every project with an account has a headless data layer. Data lives in Perafly, and your site reaches it at https://api.perafly.com/v1/projects/{project}/data/{collection}. Typical uses:
- Forms and lists: a static site collects a waitlist, contact form or survey. Public
create, secretread. - Content: posts or products live in a collection; the site reads them at build or request time, and a change hook refreshes it.
- App data: a server app (for example Next.js) reads and writes with the secret key.
Queries are deliberately simple: equality and range filters, sorting and paging. There are no joins. A project that needs a full relational database connects its own through environment variables. Projects published without an account have no data layer.
Collections
A collection is a set of records with a schema. Its name matches ^[a-z][a-z0-9_-]{0,63}$ and is unique in the project. A collection has up to 100 fields; id, createdAt and updatedAt are reserved for the system.
Filtering and sorting work only on indexed fields and on id, createdAt and updatedAt. A collection can have up to 5 indexed fields; json and file can't be indexed. A field's type (and a relation's target) can't change: delete the field and add a new one. One record is at most 64 KB.
perafly data collections update <name> --schema <file> takes the full field list. Removing a collection deletes its records too.
Rules
Each collection has a rule per action (read, create, update, delete): public lets the publishable key do it from a browser, secret needs the secret key or a team credential. Without rules, everything is secret.
create public, but not read, update or delete (rule_requires_person).Project keys
The secret key and the hook secret become environment variables of the project and take effect from the next version. The publishable key is also available as PERAFLY_PUBLISHABLE_KEY. Creating or rotating keys needs a person's sign-in; agents can't.
Reading and writing records
A record is a flat object: the system fields id (rec_…), createdAt, updatedAt and the fields of the schema. Send keys as Authorization: Bearer <key>. The API accepts browser requests from any origin.
From a static page
From a server
PATCH changes only the fields you send; null removes a field (a required field can't be removed). Unknown fields, missing required fields and wrong types answer validation_error; a relation to a missing record answers relation_not_found.
Limits and requests
- Collections per project, records per project and monthly data requests come from your plan; see Pricing. Requests from the dashboard don't count.
- When a plan without overage runs out of data requests, the API answers
data_quota_exceededuntil the next period. Plans with overage keep serving and bill the extra requests. - Rate limits: with the publishable key, 30 writes and 300 reads a minute per address and project; with the secret key, 600 requests a minute per project.
- Export (CSV or JSON) needs the plan's data export feature and can't be done with the publishable key.
Change hooks
A collection can call your site when a record is created, updated or deleted, for example to rebuild a page. Set hook: { path, events } on the collection; Perafly sends a POST to your live address plus path. Hooks need a plan with the change hooks feature.
type is record.created, record.updated or record.deleted (on delete, record is only { id }). Headers: Perafly-Event, Perafly-Delivery (hkd_…) and Perafly-Signature. A delivery that doesn't get a 2xx within 10 seconds is retried after 1 minute, 5 minutes, 30 minutes, 2 hours and 6 hours (at most 6 attempts); redirects aren't followed. perafly data hooks shows the last 50 deliveries.
Verify the signature
Perafly-Signature is t=<unix seconds>,v1=<hex>, where v1 is the HMAC-SHA256 of "<t>.<raw body>" with the hook secret. Compute it over the raw body before parsing, compare in constant time and reject a t older than 5 minutes.