RecCall provides enterprise-grade REST API servers for team deployments using Express.js and Fastify frameworks. These API servers enable centralized shortcut management, multi-user access, and integration with existing enterprise infrastructure.
npm install express @types/expressimport express from 'express';
import { createCoreEngine } from '@reccaller-ai/core';
import { createReccallMiddleware } from '@reccaller-ai/adapters/api/express';
const app = express();
app.use(express.json());
const engine = await createCoreEngine();
await engine.initialize();
// Setup RecCall API routes
createReccallMiddleware({
engine,
basePath: '/api/reccall',
}).then((middleware) => {
app.use(middleware);
});
app.listen(3000, () => {
console.log('RecCall API server running on http://localhost:3000');
});import { createReccallMiddleware } from '@reccaller-ai/adapters/api/express';
const middleware = await createReccallMiddleware({
engine,
basePath: '/api/reccall',
authenticate: async (req) => {
// Custom authentication logic
const token = req.headers.authorization?.replace('Bearer ', '');
return await validateToken(token);
},
});List all shortcuts.
Response:
{
"shortcuts": [
{
"shortcut": "example-shortcut",
"context": "Example context",
"createdAt": "2024-01-01T00:00:00.000Z",
"updatedAt": "2024-01-01T00:00:00.000Z"
}
]
}Get a specific shortcut by ID.
Response:
{
"shortcut": "example-shortcut",
"context": "Example context"
}Create a new shortcut.
Request:
{
"shortcut": "new-shortcut",
"context": "New context content"
}Update an existing shortcut.
Request:
{
"context": "Updated context content"
}Delete a shortcut.
Purge all shortcuts.
Search shortcuts by query.
List available recipes from repository.
Install a recipe from repository.
Request:
{
"repoUrl": "https://contexts.reccaller.ai"
}Get engine statistics.
Health check endpoint.
npm install fastifyimport Fastify from 'fastify';
import { createCoreEngine } from '@reccaller-ai/core';
import reccallFastifyPlugin from '@reccaller-ai/adapters/api/fastify';
const fastify = Fastify({ logger: true });
const engine = await createCoreEngine();
await engine.initialize();
await fastify.register(reccallFastifyPlugin, {
engine,
basePath: '/api/reccall',
});
await fastify.listen({ port: 3000 });await fastify.register(reccallFastifyPlugin, {
engine,
basePath: '/api/reccall',
authenticate: async (request) => {
const token = request.headers.authorization?.replace('Bearer ', '');
return await validateToken(token);
},
});FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
COPY dist ./dist
COPY starter-pack ./starter-pack
EXPOSE 3000
CMD ["node", "dist/server.js"]version: '3.8'
services:
reccall-api:
build: .
ports:
- "3000:3000"
environment:
- NODE_ENV=production
- REDIS_URL=redis://redis:6379
- POSTGRES_URL=postgresql://postgres:password@postgres:5432/reccall
depends_on:
- redis
- postgres
redis:
image: redis:7-alpine
ports:
- "6379:6379"
postgres:
image: postgres:15-alpine
environment:
- POSTGRES_DB=reccall
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
ports:
- "5432:5432"apiVersion: apps/v1
kind: Deployment
metadata:
name: reccall-api
spec:
replicas: 3
selector:
matchLabels:
app: reccall-api
template:
metadata:
labels:
app: reccall-api
spec:
containers:
- name: reccall-api
image: reccall/api:latest
ports:
- containerPort: 3000
env:
- name: REDIS_URL
valueFrom:
secretKeyRef:
name: reccall-secrets
key: redis-url
- name: POSTGRES_URL
valueFrom:
secretKeyRef:
name: reccall-secrets
key: postgres-url
---
apiVersion: v1
kind: Service
metadata:
name: reccall-api
spec:
selector:
app: reccall-api
ports:
- port: 80
targetPort: 3000
type: LoadBalancerimport { RedisStorage } from '@reccaller-ai/storage-backends/redis';
import { createCoreEngine } from '@reccaller-ai/core';
const redisStorage = new RedisStorage({
url: process.env.REDIS_URL || 'redis://localhost:6379',
});
const engine = await createCoreEngine({
storage: redisStorage,
});import { PostgresStorage } from '@reccaller-ai/storage-backends/postgres';
import { createCoreEngine } from '@reccaller-ai/core';
const postgresStorage = new PostgresStorage({
connectionString: process.env.POSTGRES_URL,
});
await postgresStorage.initialize();
const engine = await createCoreEngine({
storage: postgresStorage,
});import { WebhookManager } from '@reccaller-ai/core/webhooks';
const webhookManager = new WebhookManager(true);
webhookManager.register('slack-notifications', {
url: 'https://hooks.slack.com/services/YOUR/WEBHOOK/URL',
secret: process.env.WEBHOOK_SECRET,
events: ['shortcut.recorded', 'shortcut.deleted'],
});
// Trigger webhook
await webhookManager.trigger('shortcut.recorded', {
shortcut: 'example',
context: 'Example context',
});import { telemetryManager } from '@reccaller-ai/core/telemetry';
import express from 'express';
const app = express();
app.get('/metrics', (req, res) => {
res.set('Content-Type', 'text/plain');
res.send(telemetryManager.exportPrometheusMetrics());
});- Authentication: Always implement authentication middleware
- HTTPS: Use HTTPS for all API endpoints
- Rate Limiting: Implement rate limiting for public APIs
- Input Validation: Validate all input data
- Secret Management: Use environment variables or secret management services
- CORS: Configure CORS appropriately for your use case
The API server provides a health check endpoint at /api/reccall/health that returns:
{
"status": "ok",
"timestamp": "2024-01-01T00:00:00.000Z"
}Use the Prometheus metrics endpoint for monitoring:
reccall_shortcuts_count: Total number of shortcutsreccall_cache_hit_rate: Cache hit rate (0-1)reccall_cache_size: Current cache sizereccall_repository_enabled: Whether repository is enabledreccall_last_activity_timestamp: Last activity timestamp
- Connection Pooling: Use connection pooling for database backends
- Caching: Enable Redis caching for frequently accessed shortcuts
- Load Balancing: Deploy multiple instances behind a load balancer
- CDN: Use CDN for static assets if applicable
- Connection Errors: Check database/Redis connection strings
- Authentication Failures: Verify token validation logic
- Performance Issues: Enable caching and connection pooling
- Memory Leaks: Monitor memory usage and implement proper cleanup