Skip to main content
Custom routes allow you to extend PocketBase’s REST API with your own endpoints. You can use them to implement custom business logic, integrate with external services, or create specialized APIs.

Basic routing

In Go

Add custom routes in the OnServe hook:

In JavaScript

Use the routerAdd() function:
pb_hooks/routes.pb.js

HTTP methods

PocketBase supports all standard HTTP methods:

Path parameters

Capture dynamic segments from the URL path:

Query parameters

Access URL query string parameters:

Request body

Parse JSON request bodies:

Response types

JSON responses

String/HTML responses

File responses

Redirects

Middlewares

Middlewares allow you to process requests before they reach your handler:

Built-in middlewares

PocketBase provides several useful middlewares:

Custom middlewares

Error handling

Complete example

Here’s a complete CRUD API example:

Next steps

Event hooks

Learn about event hooks for more control

JavaScript hooks

Explore JavaScript hook examples