DEV Community

Alex Spinov
Alex Spinov

Posted on

PocketBase Has a Free API: Build a Full Backend in a Single Go Binary

What is PocketBase?

PocketBase is an open-source backend in a single file — SQLite database, REST API, auth, file storage, and admin dashboard. One binary. No dependencies. No Docker.

Perfect for MVPs, side projects, and mobile app backends.

Quick Start

# Download
wget https://github.com/pocketbase/pocketbase/releases/latest/download/pocketbase_linux_amd64.zip
unzip pocketbase_linux_amd64.zip
./pocketbase serve
Enter fullscreen mode Exit fullscreen mode

Admin: http://localhost:8090/_/ | API: http://localhost:8090/api/

The REST API

Collections (Tables)

Create collections in the admin UI, then use the API:

# List records
curl -s "http://localhost:8090/api/collections/posts/records?page=1&perPage=20"

# Get single record
curl -s "http://localhost:8090/api/collections/posts/records/RECORD_ID"

# Create record
curl -X POST "http://localhost:8090/api/collections/posts/records" \
  -H "Content-Type: application/json" \
  -d '{"title": "Hello World", "content": "My first post", "published": true}'

# Update record
curl -X PATCH "http://localhost:8090/api/collections/posts/records/RECORD_ID" \
  -d '{"title": "Updated Title"}'

# Delete record
curl -X DELETE "http://localhost:8090/api/collections/posts/records/RECORD_ID"
Enter fullscreen mode Exit fullscreen mode

Filter, Sort, Expand

# Filter
curl "http://localhost:8090/api/collections/posts/records?filter=(published=true && views>100)"

# Sort
curl "http://localhost:8090/api/collections/posts/records?sort=-created,title"

# Expand relations
curl "http://localhost:8090/api/collections/posts/records?expand=author,comments(post)"
Enter fullscreen mode Exit fullscreen mode

Auth

# Register
curl -X POST "http://localhost:8090/api/collections/users/records" \
  -d '{"email": "user@example.com", "password": "12345678", "passwordConfirm": "12345678"}'

# Login
curl -X POST "http://localhost:8090/api/collections/users/auth-with-password" \
  -d '{"identity": "user@example.com", "password": "12345678"}'
# Returns: {"token": "...", "record": {...}}

# Use token
curl "http://localhost:8090/api/collections/posts/records" \
  -H "Authorization: Bearer YOUR_TOKEN"
Enter fullscreen mode Exit fullscreen mode

File Upload

curl -X POST "http://localhost:8090/api/collections/posts/records" \
  -H "Authorization: Bearer TOKEN" \
  -F 'title=My Post' \
  -F 'image=@photo.jpg'

# Access file
# http://localhost:8090/api/files/COLLECTION/RECORD_ID/filename.jpg
Enter fullscreen mode Exit fullscreen mode

JavaScript SDK

import PocketBase from "pocketbase";

const pb = new PocketBase("http://localhost:8090");

// Auth
await pb.collection("users").authWithPassword("user@example.com", "12345678");

// CRUD
const posts = await pb.collection("posts").getList(1, 20, {
  filter: 'published = true',
  sort: '-created',
  expand: 'author',
});

const post = await pb.collection("posts").create({
  title: "New Post",
  content: "Hello!",
  published: true,
});

await pb.collection("posts").update(post.id, { title: "Updated" });

// Real-time
pb.collection("posts").subscribe("*", (e) => {
  console.log(e.action, e.record);
});
Enter fullscreen mode Exit fullscreen mode

Real-Time Subscriptions

// Subscribe to changes
pb.collection("messages").subscribe("*", (e) => {
  if (e.action === "create") {
    addMessage(e.record);
  }
});

// Unsubscribe
pb.collection("messages").unsubscribe();
Enter fullscreen mode Exit fullscreen mode

SSE-based real-time — perfect for chat apps, live dashboards.

PocketBase vs Alternatives

Feature PocketBase Supabase Firebase
Self-host Single binary Docker No
Database SQLite PostgreSQL Firestore
Auth Built-in Built-in Built-in
File storage Built-in Built-in Built-in
Real-time SSE WebSocket WebSocket
Free Yes Free tier Free tier
Setup time 10 seconds 5 minutes 5 minutes

Need a quick backend or MVP development?

📧 spinov001@gmail.com
🔧 My tools on Apify Store

PocketBase, Supabase, or Firebase? Share your backend choice!

Top comments (0)