DEV Community

Alex Spinov
Alex Spinov

Posted on

PocketBase Has a Free API You Should Know About

PocketBase is a single binary that gives you a full backend: REST API, realtime subscriptions, auth, file storage, and admin dashboard.

Instant REST API

Create a collection in the admin UI, and you immediately get full CRUD:

# List records
curl 'http://127.0.0.1:8090/api/collections/posts/records?page=1&perPage=20'

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

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

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

JavaScript SDK

import PocketBase from 'pocketbase'

const pb = new PocketBase('http://127.0.0.1:8090')

// Auth
await pb.collection('users').authWithPassword('user@test.com', 'password')

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

const newPost = await pb.collection('posts').create({
  title: 'New Post',
  content: 'Content here',
  author: pb.authStore.model.id
})
Enter fullscreen mode Exit fullscreen mode

Realtime Subscriptions

// Subscribe to changes
pb.collection('messages').subscribe('*', (e) => {
  console.log(e.action) // 'create', 'update', 'delete'
  console.log(e.record)

  if (e.action === 'create') {
    messages = [...messages, e.record]
  }
})

// Subscribe to specific record
pb.collection('posts').subscribe('RECORD_ID', (e) => {
  console.log('Post updated:', e.record)
})

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

File Uploads

const formData = new FormData()
formData.append('title', 'My Photo')
formData.append('image', fileInput.files[0])

const record = await pb.collection('gallery').create(formData)
const imageUrl = pb.files.getUrl(record, record.image)
Enter fullscreen mode Exit fullscreen mode

Custom Backend Hooks (Go)

// main.go — extend PocketBase with custom logic
func main() {
    app := pocketbase.New()

    app.OnRecordAfterCreateRequest("orders").Add(func(e *core.RecordCreateEvent) error {
        // Send notification after order created
        return sendOrderNotification(e.Record)
    })

    app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
        e.Router.GET("/api/custom/stats", func(c echo.Context) error {
            stats := computeStats(app.Dao())
            return c.JSON(200, stats)
        })
        return nil
    })

    app.Start()
}
Enter fullscreen mode Exit fullscreen mode

Real-World Use Case

An indie hacker needed a backend for their SaaS MVP: user auth, data storage, file uploads, realtime updates. Instead of Firebase ($$$) or building from scratch (weeks), they downloaded PocketBase (1 binary, 15MB), ran it, and had a full backend in 10 minutes. It runs on a $5 VPS handling 10K users.

PocketBase is the backend-in-a-box that actually works.


Build Smarter Data Pipelines

Need to scrape websites, extract APIs, or automate data collection? Check out my ready-to-use scrapers on Apify — no coding required.

Custom scraping solution? Email me at spinov001@gmail.com — fast turnaround, fair prices.

Top comments (0)