Skip to main content
PocketBase is designed to be extended and customized to fit your specific needs. You can extend it in three primary ways:

Extension methods

Go framework

Use PocketBase as a Go framework for full control

JavaScript hooks

Write hooks in JavaScript for quick customization

Event hooks

React to application events with Go handlers

When to use each approach

Go framework

Use PocketBase as a Go framework when you need:
  • Full control over the application lifecycle
  • Maximum performance for custom logic
  • Access to the complete Go ecosystem
  • Custom commands and CLI tools
  • Complex business logic that benefits from strong typing

JavaScript hooks

Use JavaScript hooks when you need:
  • Rapid prototyping and iteration
  • Dynamic code reloading during development
  • Simpler deployment (no recompilation required)
  • Access to npm packages and the JavaScript ecosystem
  • Quick customization without Go knowledge

Event hooks

Use event hooks (in Go) when you need:
  • To intercept and modify default behavior
  • To add validation or business logic
  • To trigger side effects (emails, webhooks, etc.)
  • To integrate with external services
  • To customize API responses

Common use cases

Add custom endpoints to your PocketBase server:
  • Go: Use app.OnServe() to register routes with full control
  • JavaScript: Use routerAdd() to quickly add endpoints
See Custom routes for details.
Validate or transform data before it’s saved:
  • Go: Use app.OnRecordCreate(), app.OnRecordUpdate() hooks
  • JavaScript: Use onRecordCreate(), onRecordUpdate() hooks
See Event hooks for all available events.
Integrate with external services and APIs:
  • Go: Full HTTP client control with the standard library
  • JavaScript: Use $http.send() for HTTP requests
Both approaches support webhooks, email notifications, and third-party integrations.
Implement custom authentication logic:
  • Intercept auth events with OnRecordAuthRequest
  • Add custom OAuth2 providers
  • Implement multi-factor authentication
  • Create custom password policies
Run background jobs on a schedule:
  • Go: Use app.Cron() to register cron jobs
  • JavaScript: Use cronAdd() for scheduled tasks
Perfect for data cleanup, report generation, and periodic syncs.

Architecture overview

PocketBase’s extensibility is built on a hook-based architecture: At each stage, you can inject custom logic:
  1. Router level: Add custom routes and endpoints
  2. Middleware level: Process requests before they reach handlers
  3. Event hooks: React to or modify core operations
  4. Database level: Execute custom queries and transactions

Development workflow

1

Choose your approach

Decide whether to use Go, JavaScript, or both based on your requirements.
2

Set up your environment

  • For Go: Set up a Go project with PocketBase as a dependency
  • For JavaScript: Create a pb_hooks directory in your project
3

Implement your extensions

Write your custom code using the appropriate APIs and hooks.
4

Test your changes

Use PocketBase’s built-in development mode to test your extensions.
5

Deploy

  • Go: Compile to a binary and deploy
  • JavaScript: Deploy the pb_hooks directory alongside your executable

Next steps

Go framework guide

Learn how to use PocketBase as a Go framework

JavaScript hooks guide

Get started with JavaScript hooks

Event hooks reference

Explore all available event hooks

Custom routes

Add custom API endpoints