Endpoints
Server endpoint URLs configuration for sync operations.
Import
import type { Endpoints } from '@gluonic/client'Type Definition
Exact definition from implementation:
export type Endpoints = {
bootstrapUrl: string
deltaUrl: string
wsUrl: string
}Fields
bootstrapUrl
bootstrapUrl: stringDescription: HTTP endpoint for initial bootstrap (complete snapshot)
Format: Full URL or path
Example: 'https://api.example.com/sync/v1/bootstrap' or '/sync/v1/bootstrap'
Used by: DownsyncAdapter.fetchBootstrap()
deltaUrl
deltaUrl: stringDescription: HTTP endpoint for delta sync (incremental updates)
Format: Full URL or path
Example: 'https://api.example.com/sync/v1/delta' or '/sync/v1/delta'
Used by: DownsyncAdapter.fetchDelta()
wsUrl
wsUrl: stringDescription: WebSocket endpoint for real-time updates
Format: Full WebSocket URL (wss:// or ws://)
Example: 'wss://api.example.com/sync/v1/ws' or 'ws://localhost:3000/sync/v1/ws'
Used by: RealtimeAdapter.connect()
Complete Example
const endpoints: Endpoints = {
bootstrapUrl: 'https://api.example.com/sync/v1/bootstrap',
deltaUrl: 'https://api.example.com/sync/v1/delta',
wsUrl: 'wss://api.example.com/sync/v1/ws'
}Usage
Automatic (from server URL)
SyncClient automatically constructs endpoints from base URL:
const client = SyncClient({
server: 'https://api.example.com/sync/v1',
storage,
models
})
// Internally creates:
// {
// bootstrapUrl: 'https://api.example.com/sync/v1/bootstrap',
// deltaUrl: 'https://api.example.com/sync/v1/delta',
// wsUrl: 'wss://api.example.com/sync/v1/ws'
// }Custom Endpoints
Provide custom endpoints for different servers:
const client = SyncClient({
server: {
http: 'https://api.example.com/sync/v1',
websocket: 'wss://ws.example.com/sync/v1/ws'
},
storage,
models
})
// Or provide complete endpoints object
const client = SyncClient({
server: {
bootstrapUrl: 'https://api.example.com/sync/v1/bootstrap',
deltaUrl: 'https://api.example.com/sync/v1/delta',
wsUrl: 'wss://realtime.example.com/ws'
},
storage,
models
})Common Patterns
Development vs Production
const isDev = process.env.NODE_ENV === 'development'
const client = SyncClient({
server: isDev
? 'http://localhost:3000/sync/v1'
: 'https://api.production.com/sync/v1',
storage,
models
})Separate HTTP and WebSocket Servers
const client = SyncClient({
server: {
http: 'https://api.example.com/sync/v1',
websocket: 'wss://realtime.example.com/sync/v1/ws'
},
storage,
models
})
// Results in:
// bootstrapUrl: 'https://api.example.com/sync/v1/bootstrap'
// deltaUrl: 'https://api.example.com/sync/v1/delta'
// wsUrl: 'wss://realtime.example.com/sync/v1/ws'Custom Paths
const client = SyncClient({
server: {
bootstrapUrl: '/api/v2/sync/initial',
deltaUrl: '/api/v2/sync/changes',
wsUrl: 'wss://api.example.com/realtime'
},
storage,
models
})Server Implementation
Endpoints should be implemented by your sync server:
// Server setup
import { SyncServer } from '@gluonic/server'
import { PrismaAdapter } from '@gluonic/server-prisma'
const server = SyncServer({
database: PrismaAdapter({ prisma }),
auth
})
await server.listen({ port: 3000 })
// Creates these endpoints:
// POST /sync/v1/bootstrap
// GET /sync/v1/delta?since=<sid>
// WS /sync/v1/wsSee Also
- SyncClient - Configure endpoints
- DownsyncAdapter - Uses HTTP endpoints
- RealtimeAdapter - Uses WebSocket endpoint
- Server Setup - Server endpoint implementation