Quickstart
Once Resta is running, you need three things to query a database: an API key, a database, and a token for that database. This page takes you from a running server to a first query. To get a server running, see Install on Coolify or Install with Docker Compose.
The examples use https://db.example.com as the server’s address. Replace it with yours.
1. Create your account
Open your server’s address in a browser. The first visit shows Set up this server: enter an email and a password of at least 10 characters. This is the only account on the server; signup closes once it exists.
2. Create an API key
In the dashboard, open API keys and choose New key. Copy the key, which starts with blk_. It is shown once.
export RESTA_API_KEY=blk_...
API keys have full access. Keep them on your backend, never in a browser or mobile app.
3. Create a database
curl -X POST https://db.example.com/v1/databases \
-H "Authorization: Bearer $RESTA_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "notes"}'
{"name": "notes", "id": "notes-9cbfaa9b", "status": "active", "url": "https://db.example.com/db/notes-9cbfaa9b", "created_at": 1793430777}
Names use a-z, 0-9 and -, up to 40 characters. The id adds a short random suffix; the url is what clients connect to.
4. Create a token for it
curl -X POST https://db.example.com/v1/databases/notes/tokens \
-H "Authorization: Bearer $RESTA_API_KEY" \
-H "Content-Type: application/json" \
-d '{"access": "rw", "ttl_secs": 3600}'
{"token": "eyJ...", "expires_at": 1793434377}
access is rw (read and write) or ro (read only). ttl_secs is the lifetime in seconds, up to 30 days by default.
5. Query it
npm install @tursodatabase/serverless
import { connect } from '@tursodatabase/serverless';
const db = connect({
url: 'https://db.example.com/db/notes-9cbfaa9b',
authToken: process.env.RESTA_DB_TOKEN,
});
await db.exec('CREATE TABLE IF NOT EXISTS notes (id INTEGER PRIMARY KEY, body TEXT)');
await db.run('INSERT INTO notes (body) VALUES (?)', 'hello');
console.log(await db.all('SELECT * FROM notes'));
You can also run SQL in the dashboard: open the database and choose Console.
Next
- Connecting from code: transactions, batches, streaming, and plain HTTP.
- Backups and restore: make sure your backups leave the server.