Base URLs
TrailBase REST APIs are organized into the following base paths:- Authentication:
/api/auth/v1 - Records:
/api/records/v1 - Transactions:
/api/transaction/v1 - Query:
/api/query/v1 - Admin:
/api/_admin
https://your-instance.com/api/auth/v1/login).
Versioning
TrailBase uses path-based versioning. The current API version isv1 and is included in the base path for all public APIs.
- Authentication APIs:
/api/auth/v1/* - Records APIs:
/api/records/v1/*
/api/auth/v2, /api/records/v2, etc., while maintaining backward compatibility.
Authentication
TrailBase supports multiple authentication methods:Bearer Token Authentication
Include the JWT auth token in theAuthorization header:
Cookie-Based Authentication
For web applications hosted on the same origin, TrailBase automatically sets cookies:auth_token: Short-lived JWT token for authenticationrefresh_token: Long-lived token for refreshing auth tokens
CSRF Protection
For state-changing operations (POST, PATCH, DELETE), you may need to include the CSRF token in theCSRF-Token header when using cookie-based authentication.
Token Refresh
Include the refresh token in theRefresh-Token header:
Request Formats
TrailBase accepts multiple request content types:JSON (application/json)
Form Data (application/x-www-form-urlencoded)
Multipart Form Data (multipart/form-data)
Used for file uploads:Response Formats
All responses are in JSON format with appropriate HTTP status codes.Success Response
Error Response
In production mode, error messages are intentionally minimal to avoid leaking internal details. Debug mode provides more detailed error information.
Error Handling
TrailBase uses standard HTTP status codes to indicate success or failure:Success Codes
Request succeeded, response body contains the result.
Resource created successfully.
Redirect to another URL (typically after successful form submission).
Client Error Codes
Invalid request parameters, malformed JSON, or constraint violation.
Authentication required but not provided or invalid.
Authenticated but not authorized to access the resource.
Resource or API endpoint not found.
API not found or HTTP method not supported for this endpoint.
Resource already exists (e.g., duplicate registration).
External dependency failed (e.g., email service unavailable).
Rate limit exceeded.
Server Error Codes
Unexpected server error occurred.
Database Constraint Errors
When database constraints are violated, TrailBase returns400 Bad Request with specific error messages:
db constraint: check- CHECK constraint faileddb constraint: fk- Foreign key constraint faileddb constraint: not null- NOT NULL constraint faileddb constraint: pk- Primary key constraint faileddb constraint: unique- UNIQUE constraint failed
Rate Limiting
Certain endpoints (like password reset and email verification) are rate-limited to prevent abuse. Exceeding rate limits returns429 Too Many Requests.
CORS
TrailBase supports Cross-Origin Resource Sharing (CORS) for web applications. Configure CORS settings in your TrailBase configuration.Pagination
List endpoints support cursor-based pagination:Number of records to return (default varies by API, configurable hard limit)
Encrypted cursor from previous response for fetching the next page
Zero-based offset for pagination (alternative to cursor)
Filtering
Records API supports filtering via query parameters:Ordering
Results can be ordered by specifying column names:Best Practices
- Always use HTTPS in production to protect authentication tokens
- Store tokens securely - never expose tokens in client-side code or logs
- Implement token refresh to maintain sessions without re-authentication
- Handle errors gracefully - check status codes and parse error messages
- Use appropriate content types - JSON for most requests, multipart for file uploads
- Respect rate limits - implement exponential backoff for retry logic
- Validate inputs on the client side to reduce unnecessary API calls