Tenum Help

Message Handlers (mh)

The Message Handler Artifact (mh)

Filetype:{filename}.mh.lua

This artifact is used to create an endpoint in the backend. It usually holds the business logic of your application. Message Handlers are never loaded into the browser and are always executed as part of your backend.

TENUM® Usage Sample**

Sample App: **TENUM®** ToDo App

Sample Message Handler: createToDo.mh.lua

local export = {} local todoList = require("todo.api.todoList") local todo = require("todo.api.todo") function export.handle(props) local listId = props.listId if not listId then error("listId is required to export todos") end local todos = todoList.queries.getTodos{ id = listId } local result = {} for _, todoId in ipairs(todos) do local entity = todo.queries.getTodo{ id = todoId } if entity then table.insert(result, { id = todoId, title = entity.title, completed = entity.completed }) end end return result end return export

Best Practices

  1. Validate Incoming Requests

    • Always use validators to ensure incoming HTTP requests meet expected criteria before processing.

  2. Keep Handlers Small

    • Design each message handler with a single responsibility to maintain clarity and simplicity.

  3. Delegate Business Logic

    • Avoid embedding complex logic directly in the handler; instead, delegate to entities for state management or trigger events when necessary.

  4. Implement Robust Error Handling

    • Include proper error handling to return clear, meaningful feedback to the caller, improving reliability and debugging.

  5. Leverage the TENUM® Ecosystem

    • Use shared modules for common operations, decorators for cross-cutting concerns (e.g., logging, authentication), and rely on TENUM® ’s built-in scalability for handling high-concurrency workloads.

Last modified: 11 April 2025