API & Connection

Connection credentials and usage examples for your project.

Connection Details

/rest/v1
Loading API keys…
⚠ Never expose the Service Role Key on the client side. Use it only in server-side code.

Connect with AI / LLM

Give your AI assistant access to query and manage this project's database.

Add this to your CLAUDE.md so Claude Code knows how to connect to this project.

Add to CLAUDE.md
markdown
# xBase Project: qrs5551234

## Credentials

```env
XBASE_URL=
XBASE_ANON_KEY=loading…
XBASE_SERVICE_KEY=loading…
```

## REST API (DML — SELECT, INSERT, UPDATE, DELETE)

Base URL: `/rest/v1`

Required headers:
- `Authorization: Bearer <anon-key>`  ← use anon-key for reads
- `Authorization: Bearer <service-key>` ← use service-key for writes without RLS

```bash
# SELECT
curl '/rest/v1/{table}?select=col1,col2&status=eq.active' \
  -H "Authorization: Bearer loading…"

# INSERT
curl -X POST '/rest/v1/{table}' \
  -H "Authorization: Bearer loading…" \
  -H "Content-Type: application/json" \
  -d '{"column":"value"}'

# UPDATE
curl -X PATCH '/rest/v1/{table}?id=eq.1' \
  -H "Authorization: Bearer loading…" \
  -H "Content-Type: application/json" \
  -d '{"column":"new_value"}'

# DELETE
curl -X DELETE '/rest/v1/{table}?id=eq.1' \
  -H "Authorization: Bearer loading…"
```

## SQL Endpoint (DDL — CREATE TABLE, ALTER, migrations)

**IMPORTANT:** Use `/rpc/sql` (NOT `/rest/v1/rpc/sql`) with service-key only.

```bash
curl -X POST '/rpc/sql' \
  -H "Authorization: Bearer loading…" \
  -H "Content-Type: application/json" \
  -d '{"query": "CREATE TABLE posts (id uuid PRIMARY KEY DEFAULT gen_random_uuid(), title text NOT NULL)"}'
```

Response: `{"rows": [...], "rowCount": N, "command": "SELECT|INSERT|CREATE|..."}`

## Filter operators (REST API)

| Operator | Meaning     | Example                         |
|----------|-------------|----------------------------------|
| eq       | =           | `?status=eq.active`           |
| neq      | !=          | `?role=neq.admin`             |
| lt/gt    | < / >       | `?age=gt.18`                  |
| lte/gte  | <= / >=     | `?price=lte.100`              |
| like     | LIKE        | `?name=like.*silva*`          |
| ilike    | ILIKE       | `?email=ilike.*@gmail.com`    |
| is       | IS NULL/TRUE| `?deleted_at=is.null`         |
| in       | IN (...)    | `?id=in.(1,2,3)`              |

REST API

xBase auto-generates a REST API via PostgREST for every table in your database.

typescript
import { createClient } from '@xbase/client'

const xbase = createClient('', 'loading…')

// SELECT
const { data, error } = await xbase
  .from('users')
  .select('id, name, email')
  .eq('active', true)
  .order('created_at', { ascending: false })
  .limit(10)

// INSERT
await xbase.from('posts').insert({ title: 'Hello', body: '…' })

// Realtime subscription
xbase.from('orders').on('INSERT', (event) => {
  console.log('New order:', event.new)
}).subscribe()

Realtime

WebSocket endpoint for real-time subscriptions via WAL replication.

/realtime/v1/websocket

REST Endpoints

GET/rest/v1/{table}Query rows with filters, order and pagination
POST/rest/v1/{table}Insert one or multiple rows
PATCH/rest/v1/{table}Update rows matching filters
DELETE/rest/v1/{table}Delete rows matching filters
POST/rest/v1/rpc/{fn}Call a stored procedure / RPC function
POST/rpc/sqlExecute raw SQL (service_role key only)
POST/auth/v1/tokenIssue a JWT token (user login)