API & Connection
Connection credentials and usage examples for your project.
Connection Details
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: xyz9876543
## 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.
REST Endpoints
GET
/rest/v1/{table}Query rows with filters, order and paginationPOST
/rest/v1/{table}Insert one or multiple rowsPATCH
/rest/v1/{table}Update rows matching filtersDELETE
/rest/v1/{table}Delete rows matching filtersPOST
/rest/v1/rpc/{fn}Call a stored procedure / RPC functionPOST
/rpc/sqlExecute raw SQL (service_role key only)POST
/auth/v1/tokenIssue a JWT token (user login)