Build

Data API

Your app reads and writes its tables over HTTPS, straight from the browser or from a server, with a publishable key. Each table has its own address, with filters, order and pages in the query string, and there is nothing to run.

Turn it on

Open Data API in the Kaiva Cloud console, choose a database and turn it on. It gets an address for your app and a publishable key. The key is shown once, so copy it into your app then. Every table stays closed until you give it a rule.

Owners and admins can turn the Data API on and change its key, websites and rules.

The address and the key

Copy the address from the database's Data API page and add a table's name to it. Send the publishable key as the apikey header.

curl
curl "https://api.kaiv.ai/api/cloud/v1/data/YOUR_DATABASE/todos?limit=5" \
  -H "apikey: YOUR_PUBLISHABLE_KEY"

The key is safe in your app's code and in a web page: it does only what your table rules give Anyone with the key. Anyone who copies it can also spend the database's requests for the day on the tables it opens.

Make a new key at any time. The current key stops working at once, so update every app that uses it.

Read rows

JavaScript
const TABLE = 'https://api.kaiv.ai/api/cloud/v1/data/YOUR_DATABASE/todos';
const KEY = 'YOUR_PUBLISHABLE_KEY';

const res = await fetch(`${TABLE}?select=id,task&done=eq.false&order=id.desc&limit=20`, {
  headers: { apikey: KEY },
});
const { rows, more } = await res.json();

A read returns { rows, more }, where more says whether there are rows past this page. select chooses the columns, order sorts, and limit (up to 1,000 rows) and offset page through the rows.

order takes a column, then optionally asc or desc and nullsfirst or nullslast, such as order=created_at.desc. Separate several with commas.

Filters

Every query parameter other than select, order, limit and offset names a column. Its value is an operator, a dot and a value. When there are several filters, all of them must hold.

OperatorMeansExample
eqequalsstatus=eq.open
neqdoes not equalstatus=neq.closed
gt, gte, lt, ltegreater or less thancreated_at=gte.2026-01-01
like, ilikematches a pattern, * for any text (ilike ignores case)name=ilike.*smith*
isis null, true, false or unknowndeleted_at=is.null
inis one of a listid=in.(1,2,3)

Add, change and delete rows

POSTAdds one row, or a list of up to 100, sent as JSON.
PATCHChanges the rows that match its filters. It needs at least one filter.
DELETEDeletes the rows that match its filters. It needs at least one filter.
JavaScript
const TABLE = 'https://api.kaiv.ai/api/cloud/v1/data/YOUR_DATABASE/todos';
const KEY = 'YOUR_PUBLISHABLE_KEY';

const res = await fetch(TABLE, {
  method: 'POST',
  headers: {
    apikey: KEY,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ task: 'Write the docs' }),
});
const { count, rows } = await res.json();

Writes return { count, rows }, and select chooses the columns that come back. A change that would reach more than 1,000 rows is refused, and nothing is changed. Errors return { error, message }.

Table rules

On the Table rules tab, each table has one rule, with a choice for each of reading, inserting, updating and deleting rows. A table with no rule is closed to every request, and a closed table answers as if it did not exist.

ChoiceWho it lets in
NobodyNo one. Every table starts here.
Anyone with the keyAny page or script that has the publishable key
Signed-in usersRequests that carry a valid access token from sign-in
Each user's own rowsSigned-in users, limited to rows whose owner column holds their id

Updating or deleting rows also needs reading them, since a filter reads the column it compares. A view can only be read. Saving applies the rules in the database first, and the page then says in plain sentences what is open.

Signed-in users

Send the user's access token from sign-in as Authorization: Bearer, next to the publishable key.

JavaScript
const TABLE = 'https://api.kaiv.ai/api/cloud/v1/data/YOUR_DATABASE/todos';
const KEY = 'YOUR_PUBLISHABLE_KEY';

// accessToken: the signed-in user's access token from sign-in
const res = await fetch(`${TABLE}?id=eq.42`, {
  method: 'PATCH',
  headers: {
    apikey: KEY,
    Authorization: `Bearer ${accessToken}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ done: true }),
});

For Each user's own rows, choose the table's owner column: a text or uuid column that holds the user's id. Rows a user adds get their id in that column, a row naming someone else is refused, and no update changes it. A user you turn off or delete is refused at once.

Allowed websites

List the websites whose pages may use the key in a browser, such as https://app.example.com with no path after it, up to 20, or * for any website. Servers and scripts can use the key from anywhere, because the key is public: your table rules are what protect your data.

New tables and columns

New tables appear on the Table rules tab, closed, ready for a rule. New columns reach the Data API within a minute.

If the page says a table is not open in the database, the table belongs to another database role, or was made again since the rules were saved. Give it to the database's owner with ALTER TABLE … OWNER TO on the SQL tab, then choose Apply again.

Requests and turning it off

The Requests tab lists the requests your app makes to the database. Turning the Data API off refuses every request until you turn it on again; your key, websites and rules are kept.