Skip to main content

REST API reference

Every Table and View in the public Schema gets an automatic API at https://<ref>.baas.arianet.app/rest/v1/<table>. A new Table is available in the API at once. Each request runs with the role of its key or User, and RLS and Policies decide which Rows are seen or changed.

BAAS_URL=https://<ref>.baas.arianet.app
ANON_KEY=<ANON_KEY>

Headers​

HeaderValue
apikeyRequired. The Anon Key or Publishable Key (on a server: the Service Key or Secret Key).
AuthorizationBearer <access_token> when a User is signed in; the request runs as authenticated with that User's id. Without it, the key's role is used (anon or service_role).
Content-Typeapplication/json for request bodies.
PreferResponse behaviour: return=representation (return the written Rows), return=minimal, count=exact, resolution=merge-duplicates or resolution=ignore-duplicates (upsert). Separate several with commas.
RangePaging by Row range, such as Range: 0-24 (with Range-Unit: items).
Acceptapplication/json (default) or text/csv.

Roles:

RoleWithRLS
anonAnon/Publishable Key without a User tokenapplies
authenticateda User's token in Authorizationapplies; auth.uid() is that User's id
service_roleService/Secret Keybypassed

Browsers can call the API directly: responses allow CORS for any origin, because keys (not cookies) authorise requests.

Read​

GET /rest/v1/{table}​

# all columns
curl "$BAAS_URL/rest/v1/todos?select=*" -H "apikey: $ANON_KEY"

# chosen columns, with an alias and a cast
curl "$BAAS_URL/rest/v1/todos?select=id,title,createdAt:created_at,price::text" -H "apikey: $ANON_KEY"
  • select picks the columns; without it, all columns are returned. alias:column renames and column::type casts.
  • JSON columns: select=meta->color,meta->>size (-> returns JSON, ->> text).
  • Related Tables (through a foreign key) in the same request: select=id,title,author(id,name) for a to-one reference, select=id,name,todos(id,title) for the related Rows. With author!inner(name) only Rows that have a related Row are returned.
  • A response has at most 1000 Rows; for more, page through them.

Filters​

A filter is column=operator.value in the query string. Several filters are combined with AND.

OperatorMeaningExample
eqequalstatus=eq.done
neqnot equalstatus=neq.done
gt, gtegreater than, or equalprice=gte.1000
lt, lteless than, or equalcreated_at=lt.2026-12-01
like, ilikepattern (* instead of %); ilike ignores casetitle=ilike.*milk*
inone of the valuesid=in.(1,2,3)
isnull, true, falsedeleted_at=is.null
cs, cdarray/JSON contains / is contained intags=cs.{work,urgent}
ovarray or range overlaptags=ov.{a,b}
fts, plfts, phfts, wftsfull-text searchbody=fts.hello
not.negates any operatorstatus=not.eq.done
or / andcombine conditionsor=(status.eq.new,priority.gt.3)
curl "$BAAS_URL/rest/v1/todos?select=*&done=is.false&or=(priority.gte.3,title.ilike.*urgent*)" \
-H "apikey: $ANON_KEY" -H "Authorization: Bearer $TOKEN"

Put values containing commas, parentheses or dots in " and URL-encode them. Filter on a related Table: select=*,todos(*)&todos.done=eq.false.

Ordering​

order=column.asc or order=column.desc, with nullsfirst / nullslast, several columns separated by commas:

curl "$BAAS_URL/rest/v1/todos?select=*&order=done.asc,created_at.desc.nullslast" -H "apikey: $ANON_KEY"

Paging​

With limit and offset:

curl "$BAAS_URL/rest/v1/todos?select=*&order=id&limit=25&offset=50" -H "apikey: $ANON_KEY"

Or with the Range header. For the total count, send Prefer: count=exact; the response then has a Content-Range header such as 50-74/312:

curl -i "$BAAS_URL/rest/v1/todos?select=*" -H "apikey: $ANON_KEY" \
-H "Range: 0-24" -H "Prefer: count=exact"

On large Tables, count=planned or count=estimated is faster. Always page with an order so the order is stable.

Insert​

POST /rest/v1/{table}​

curl -X POST "$BAAS_URL/rest/v1/todos" \
-H "apikey: $ANON_KEY" -H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" -H "Prefer: return=representation" \
-d '{"title": "Buy bread"}'
  • For several Rows, send an array: [{"title": "a"}, {"title": "b"}].
  • Without Prefer: return=representation the answer is 201 with no body.
  • The Row must pass the WITH CHECK of an INSERT Policy, otherwise you get error 42501.
  • ?columns=title,done reads only these columns from the body.

Upsert​

Insert, or update when the key already exists:

curl -X POST "$BAAS_URL/rest/v1/profiles?on_conflict=user_id" \
-H "apikey: $ANON_KEY" -H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-H "Prefer: resolution=merge-duplicates,return=representation" \
-d '{"user_id": "<user-id>", "display_name": "Ali"}'
  • on_conflict names the unique column or columns (default: the primary key).
  • resolution=ignore-duplicates skips duplicate Rows.
  • An upsert needs both an INSERT and an UPDATE Policy.

Update​

PATCH /rest/v1/{table}​

curl -X PATCH "$BAAS_URL/rest/v1/todos?id=eq.42" \
-H "apikey: $ANON_KEY" -H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" -H "Prefer: return=representation" \
-d '{"done": true}'

Always add a filter. Without one, every Row the Policies allow is changed. Rows the UPDATE Policy does not see are left alone (without an error).

Delete​

DELETE /rest/v1/{table}​

curl -X DELETE "$BAAS_URL/rest/v1/todos?id=eq.42" \
-H "apikey: $ANON_KEY" -H "Authorization: Bearer $TOKEN"

As with updates, without a filter every allowed Row is deleted. Prefer: return=representation returns the deleted Rows.

Call a Function with rpc​

POST /rest/v1/rpc/{function}​

Any Function in the public Schema can be called. Arguments are sent as JSON by parameter name:

create function public.todo_stats(min_priority int)
returns table (done boolean, total bigint)
language sql stable
as $$
select done, count(*) from public.todos where priority >= min_priority group by done
$$;
curl -X POST "$BAAS_URL/rest/v1/rpc/todo_stats" \
-H "apikey: $ANON_KEY" -H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"min_priority": 2}'
  • stable or immutable Functions can also be called with GET and query parameters: GET /rest/v1/rpc/todo_stats?min_priority=2.
  • A Function runs as the caller and RLS applies, unless it was created security definer. In a security definer Function always set search_path = '' and check access yourself.
  • Filters, order and limit also work on the result of Functions that return a table.

Errors​

Errors about reaching the Project (before the request reaches the API) look like this:

{"code": "invalid_api_key", "message": "…", "request_id": "…"}
HTTPcodeMeaning
401no_api_keyNo apikey header was sent.
401invalid_api_keyThe key is wrong or revoked (for example an old key after a rotation's overlap).
402egress_limit_reachedThe Free Plan's monthly Egress is used up.
403project_suspendedThe Project is suspended.
404project_not_foundNo Project at this address.
429rate_limit_exceededMore requests than the Plan allows; retry after Retry-After seconds.
503project_resumingThe Project is starting after an automatic pause; retry after Retry-After (about 5 seconds).
503project_pausedYou paused the Project.
503project_provisioningThe Project is still being created.
502upstream_unavailableThe service did not answer for a moment; retry.

API and Database errors look like this:

{"code": "42501", "message": "new row violates row-level security policy for table \"todos\"", "details": null, "hint": null}

code is either the Database's own SQLSTATE (for example 42501 permission or Policy violation, 23505 duplicate value, 23503 foreign key violation, 42P01 the Table does not exist, 22P02 invalid value for the column type) or the REST layer's own code for errors such as a bad parameter. Compatible client libraries understand these codes. Every response has an X-Request-Id header; include it when you report a problem.

Other Schemas

Only the public Schema is served by the REST API. Read Tables of other Schemas through a Function in public, or from a server over the direct connection.