API Documentation
Overview
PostgSail exposes its PostgreSQL database through a RESTful API using PostgREST, which serves as the primary interface for all client interactions. The API supports three main authentication roles that determine access permissions and available endpoints.
Authentication
The API uses JWT (JSON Web Token) authentication with role-based switching. The JWT token contains claims that set session variables used by Row Level Security policies:
vessel.id- Current vessel identifieruser.email- Current user emailuser.id- Current user identifier
API Roles
api_anonymous
Unauthenticated access with read-only permissions on public data for public access when enable
user_role
Authenticated web users with full access to their vessel data.
vessel_role
SignalK plugin data ingestion with insert/update permissions.
mcp_role
Authenticated web users with read-only access to their vessel data via an Large language model.
API Endpoints
Base URL
http://localhost:3000
Authentication Examples
Anonymous access:
curl http://localhost:3000/
User role access:
curl http://localhost:3000/ -H 'Authorization: Bearer my_token_from_login_or_signup_fn'
Vessel role access:
curl http://localhost:3000/ -H 'Authorization: Bearer my_token_from_register_vessel_fn'
Key Endpoints by Role
Authentication Functions
POST /rpc/login- User authenticationPOST /rpc/signup- User registrationPOST /rpc/register_vessel- Vessel registration
Data Tables (user_role and vessel_role)
GET /metrics- Time-series telemetry dataGET /logbook- Trip records with trajectoriesGET /stays- Mooring/anchoring periodsGET /moorages- Named locationsGET /metadata- Vessel metadata including configuration
Views (user_role)
GET /logs_view- Enriched logbook dataGET /log_view- Details logbook dataGET /moorages_view- Enriched moorage dataGET /moorage_view- Details moorage dataGET /stays_view- Enriched Stays dataGET /stay_view- Details Stay dataGET /vessels_view- Vessel dataGET /monitoring_view- System monitoring data
RPC Functions
POST /rpc/settings_fn- User preferencesPOST /rpc/update_user_preferences_fn- Update preferencesPOST /rpc/versions_fn- System version informationPOST /rpc/vessel_fn- Vessel details
OpenAPI Documentation
The OpenAPI specification is dynamically generated based on the authenticated role’s permissions. Access the interactive documentation at:
https://petstore.swagger.io/?url=https://raw.githubusercontent.com/xbgmsharp/postgsail/main/openapi.json
Other applications can also use the PostgSAIL API.
The available endpoints and operations in the OpenAPI spec will vary depending on the JWT role used to access /.
Public Access
Anonymous users can access specific public data when vessel owners have enabled public sharing.
Configuration
The PostgREST service is configured via environment variables:
PGRST_DB_SCHEMA: api- Default schemaPGRST_DB_ANON_ROLE: api_anonymous- Anonymous rolePGRST_DB_PRE_REQUEST: public.check_jwt- JWT validation functionPGRST_JWT_SECRET- JWT signing secret
Notes
- The API runs on port 3000 by default
- All data access is controlled by Row Level Security policies based on vessel ownership
- The SignalK plugin uses vessel_role for continuous data ingestion
- Rate limiting and connection limits are enforced per role