• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
pinsar

pinsar

feistyAmberRhinoceros

Public
Like
feistyAmberRhinoceros
Home
Code
9
backend
5
docs
1
frontend
2
shared
2
LICENSE
README.md
gitignore
H
main.tsx
package.json
Branches
1
Pull requests
Remixes
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
docs
/
API.md
Code
/
docs
/
API.md
Search
5/26/2025
Viewing readonly version of main branch: v25
View latest version
API.md

API Documentation

Overview

The Real-Time Data Processing System provides a comprehensive REST API for event ingestion, metrics monitoring, and system management.

Base URL

https://your-deployment-url.com

Authentication

Currently, the API does not require authentication. In production, implement proper authentication and authorization.

Endpoints

Event Ingestion

POST /api/events

Ingest a single event into the processing system.

Request Body:

{ "type": "user_action", "source": "web_app", "data": { "user_id": "12345", "action": "click", "page": "/dashboard", "metadata": {} }, "timestamp": 1640995200000, "id": "optional-custom-id" }

Response:

{ "success": true, "eventId": "evt_1640995200000_abc123", "processingTime": 15.5 }

POST /api/events/batch

Ingest multiple events in a single request (max 1000 events).

Request Body:

[ { "type": "user_action", "source": "web_app", "data": { "user_id": "12345", "action": "click" } }, { "type": "page_view", "source": "web_app", "data": { "user_id": "12345", "page": "/home" } } ]

Response:

{ "success": true, "processed": 2, "failed": 0, "totalProcessingTime": 45.2, "errors": [] }

Metrics & Monitoring

GET /api/metrics

Get current system metrics.

Response:

{ "timestamp": 1640995200000, "throughput": { "eventsPerSecond": 1250.5, "batchesPerSecond": 12.3, "totalEvents": 1000000 }, "latency": { "avgProcessingTime": 15.2, "p50ProcessingTime": 12.0, "p95ProcessingTime": 45.0, "p99ProcessingTime": 89.0 }, "errors": { "errorRate": 0.001, "totalErrors": 1000, "errorsByType": { "validation_error": 500, "storage_error": 300, "processing_error": 200 } }, "system": { "processingInstances": 5, "queueDepth": 1500, "memoryUsage": 512, "cpuUsage": 65.5 }, "health": { "status": "healthy", "uptime": 86400000 } }

GET /api/metrics/history?hours=24

Get historical metrics data.

Query Parameters:

  • hours (optional): Number of hours of history to retrieve (default: 1)

GET /api/health

Get detailed system health status.

Response:

{ "status": "healthy", "timestamp": 1640995200000, "uptime": 86400000, "checks": [ { "name": "event_ingestion", "status": "pass", "message": "Event ingestion healthy: 1250.5 events/sec", "duration": 2.5, "timestamp": 1640995200000, "metadata": { "eventsPerSecond": 1250.5, "totalEvents": 1000000 } } ], "summary": { "total": 7, "passing": 7, "warning": 0, "critical": 0 } }

System Management

POST /api/load-test

Start a load test to generate synthetic events.

Request Body:

{ "eventsPerSecond": 5000, "durationSeconds": 30 }

Response:

{ "success": true, "message": "Load test started: 5000 events/sec for 30 seconds" }

POST /api/system/scale

Scale the number of processing instances.

Request Body:

{ "instances": 10 }

Response:

{ "success": true, "message": "Scaled to 10 processing instances" }

POST /api/system/reset

Reset system metrics and state.

Response:

{ "success": true, "message": "System metrics and state reset" }

Real-Time Updates

WebSocket /ws/metrics

Connect to receive real-time metrics updates.

Message Format:

{ "type": "metrics", "data": { // Same structure as GET /api/metrics }, "timestamp": 1640995200000 }

Error Responses

All endpoints return errors in the following format:

{ "success": false, "error": "Error message describing what went wrong" }

Rate Limiting

  • Event ingestion: 10,000 requests per second per instance
  • API endpoints: 1,000 requests per minute per IP
  • WebSocket connections: 10 concurrent connections per IP

Event Schema

Required Fields

  • type: String - Event type (e.g., "user_action", "page_view")
  • source: String - Event source (e.g., "web_app", "mobile_app")

Optional Fields

  • id: String - Custom event ID (auto-generated if not provided)
  • timestamp: Number - Unix timestamp in milliseconds (current time if not provided)
  • data: Object - Event payload data

Event Types

Common event types supported:

  • user_action - User interactions (clicks, scrolls, etc.)
  • page_view - Page navigation events
  • purchase - E-commerce transactions
  • signup - User registration events
  • login - Authentication events
  • api_call - API usage events
  • system_event - System-generated events
  • error_event - Error occurrences

Event Sources

Common event sources:

  • web_app - Web application
  • mobile_app - Mobile application
  • api - Direct API calls
  • load_test - Load testing
  • system - System-generated
  • external - External integrations
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.