Rohas supports multiple runtime environments for executing handlers. Currently, TypeScript and Python are supported, with each runtime providing full access to the language's ecosystem.
The TypeScript runtime uses V8 JavaScript engine (via deno_core) to execute handlers.
Features:
Handler Execution:
Example Handler:
from generated.api.Health import HealthResponse
from datetime import datetime
async def handler() -> HealthResponse:
return HealthResponse(
status="ok",
timestamp=datetime.now().isoformat()
)The Python runtime uses PyO3 for seamless Python integration.
Features:
Handler Execution:
All handlers receive a HandlerContext object containing:
from generated.runtime import HandlerContext
async def handler(context: HandlerContext) -> Response:
payload = context.payload
query_params = context.query_params
# Use context dataAPI handlers process HTTP requests and return responses.
TypeScript:
from generated.api.CreateUser import CreateUserInput, User
from datetime import datetime
async def handler(input: CreateUserInput) -> User:
# Process input
return User(
id=1,
name=input.name,
email=input.email,
created_at=datetime.now()
)Event handlers process events asynchronously.
TypeScript:
from generated.events.UserCreated import UserCreated
async def handler(event: UserCreated) -> None:
print(f"User created: {event.user_id}")
# Process eventCron handlers execute on a schedule.
TypeScript:
async def handler() -> None:
# Scheduled task logic
print("Running scheduled cleanup")WebSocket handlers manage real-time connections.
TypeScript:
from generated.websockets.Chat import WebSocketMessage
async def on_connect(context: HandlerContext) -> None:
print("Client connected")
async def on_message(message: WebSocketMessage, context: HandlerContext) -> None:
# Handle message
pass
async def on_disconnect(context: HandlerContext) -> None:
print("Client disconnected")Handlers can return errors that are automatically handled by the runtime.
async def handler() -> Response:
try:
# Your logic
return {"success": True}
except Exception as e:
raise Exception(f"Handler failed: {str(e)}")Handlers have a default timeout of 30 seconds. Timeouts are configurable per handler type.
In development mode (rohas dev or rohas dev --workbench), handlers are automatically reloaded when files change:
Install dependencies using npm/yarn/pnpm:
npm install <package>Install dependencies using pip:
pip install <package>
Add to requirements.txt:
requests==2.31.0
Import in handlers:
import requests async def handler(): response = requests.get("https://api.example.com") return response.json()
Use console.log for debugging:
import logging
logger = logging.getLogger(__name__)
async def handler():
logger.info("Debug info: %s", data)
# Handler logicgenerated/