Core API

createSurf

Create a new Surf instance

createSurf(config)#

Creates a new Surf instance. The config object defines your service name, commands, auth, events, and behavior.

typescript
import { createSurf } from '@surfjs/core'
ย 
const surf = await createSurf({
name: 'My Service',
description: 'A Surf-enabled API',
version: '1.0.0',
commands: { /* ... */ },
events: { /* ... */ },
authVerifier: myVerifier,
rateLimit: { windowMs: 60_000, maxRequests: 100 },
strict: true,
})
ย 
// Returns a SurfInstance with:
surf.manifest() // Get the generated manifest
surf.manifestHandler() // HTTP handler for /.well-known/surf.json
surf.httpHandler() // HTTP handler for /surf/execute
surf.middleware() // Combined HTTP middleware (manifest + execute + sessions + pipeline)
surf.wsHandler(server) // Attach WebSocket transport
surf.emit(event, data) // Emit an event to connected clients
surf.use(middleware) // Add a middleware function
surf.events // Access the EventBus
surf.sessions // Access the SessionStore
surf.commands // Access the CommandRegistry