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
Custom routes and APIs
Custom routes and APIs
Add custom endpoints to your PocketBase server:
- Go: Use
app.OnServe()to register routes with full control - JavaScript: Use
routerAdd()to quickly add endpoints
Data validation and transformation
Data validation and transformation
Validate or transform data before it’s saved:
- Go: Use
app.OnRecordCreate(),app.OnRecordUpdate()hooks - JavaScript: Use
onRecordCreate(),onRecordUpdate()hooks
External integrations
External integrations
Integrate with external services and APIs:
- Go: Full HTTP client control with the standard library
- JavaScript: Use
$http.send()for HTTP requests
Custom authentication
Custom authentication
Implement custom authentication logic:
- Intercept auth events with
OnRecordAuthRequest - Add custom OAuth2 providers
- Implement multi-factor authentication
- Create custom password policies
Scheduled tasks
Scheduled tasks
Run background jobs on a schedule:
- Go: Use
app.Cron()to register cron jobs - JavaScript: Use
cronAdd()for scheduled tasks
Architecture overview
PocketBase’s extensibility is built on a hook-based architecture: At each stage, you can inject custom logic:- Router level: Add custom routes and endpoints
- Middleware level: Process requests before they reach handlers
- Event hooks: React to or modify core operations
- Database level: Execute custom queries and transactions
Development workflow
Set up your environment
- For Go: Set up a Go project with PocketBase as a dependency
- For JavaScript: Create a
pb_hooksdirectory in your project
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