DEV Community

Alex Spinov
Alex Spinov

Posted on

Xata Has a Free API — Here's How to Build Full-Stack Apps with a Serverless Database

Why Xata?

Xata combines a serverless database, full-text search, and file attachments into one platform. Think of it as Airtable's ease of use meets PostgreSQL's power — with a built-in API.

Free tier: 15 GB storage, 750 requests/second, 15 GB search, 2 GB file attachments.

Getting Started

1. Sign Up & Install CLI

# Sign up at xata.io — free, no credit card
npm install -g @xata.io/cli
xata auth login
Enter fullscreen mode Exit fullscreen mode

2. Initialize Project

xata init --db https://your-workspace.xata.sh/db/my-app
Enter fullscreen mode Exit fullscreen mode

3. Define Schema

In Xata's dashboard or via schema file:

{
  "tables": [{
    "name": "posts",
    "columns": [
      {"name": "title", "type": "string"},
      {"name": "content", "type": "text"},
      {"name": "author", "type": "string"},
      {"name": "tags", "type": "multiple"},
      {"name": "published", "type": "bool", "defaultValue": "false"},
      {"name": "views", "type": "int", "defaultValue": "0"}
    ]
  }]
}
Enter fullscreen mode Exit fullscreen mode

TypeScript SDK (Type-Safe!)

import { getXataClient } from "./xata"; // auto-generated

const xata = getXataClient();

// Create records
await xata.db.posts.create({
  title: "Getting Started with Xata",
  content: "Xata is a serverless database with built-in search...",
  author: "Alice",
  tags: ["database", "serverless", "tutorial"],
  published: true
});

// Query with filters
const publishedPosts = await xata.db.posts
  .filter({ published: true })
  .sort("xata.createdAt", "desc")
  .getPaginated({ pagination: { size: 10 } });

console.log(publishedPosts.records);

// Full-text search (built-in, no extra setup!)
const results = await xata.db.posts.search("serverless database", {
  fuzziness: 1,
  prefix: "phrase"
});

results.records.forEach(r => console.log(`${r.title} (score: ${r.xata.score})`));
Enter fullscreen mode Exit fullscreen mode

REST API (No SDK Needed)

# Search
curl -X POST 'https://your-workspace.xata.sh/db/my-app:main/tables/posts/search' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"query": "serverless", "fuzziness": 1}'

# Query with filters
curl -X POST 'https://your-workspace.xata.sh/db/my-app:main/tables/posts/query' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"filter": {"published": true}, "sort": [{"xata.createdAt": "desc"}]}'
Enter fullscreen mode Exit fullscreen mode

Python Example

import requests

BASE = "https://your-workspace.xata.sh/db/my-app:main"
HEADERS = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
}

# Insert record
resp = requests.post(f"{BASE}/tables/posts/data", headers=HEADERS, json={
    "title": "Python + Xata",
    "content": "Using Xata from Python via REST API",
    "author": "Bob",
    "tags": ["python", "xata"],
    "published": True
})
print(f"Created: {resp.json()['id']}")

# Aggregate
resp = requests.post(f"{BASE}/tables/posts/aggregate", headers=HEADERS, json={
    "aggs": {
        "byAuthor": {"topValues": {"column": "author", "size": 10}},
        "totalViews": {"sum": {"column": "views"}}
    }
})
print(resp.json())
Enter fullscreen mode Exit fullscreen mode

What Makes Xata Special

Feature Xata Supabase Firebase
Database PostgreSQL PostgreSQL NoSQL
Search Built-in Extension Third-party
File storage Built-in Separate Built-in
Branching Yes No No
Type generation Auto Manual Manual
Free tier 15 GB 500 MB 1 GB

Need to scrape data and store it in Xata? I build production-ready web scrapers with structured output. Check out my Apify actors or email spinov001@gmail.com for custom solutions.

Tried Xata? Share your experience below!

Top comments (0)