Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:APIJSON APIJSON Remote Function Execution

From Leeroopedia
Knowledge Sources
Domains Remote_Functions, Script_Execution, Reflection
Last Updated 2026-10-11 00:00 GMT

Overview

A server-side execution pattern that resolves function-call syntax in API requests to registered Java methods or script functions, executes them with request-context arguments, and substitutes the results back into the response.

Description

Remote Function Execution allows API clients to invoke server-side functions by including function-call syntax in request keys (e.g., "isContain(praiseUserIdList,userId)"). The server resolves the function name, validates it against a registry, and executes it via Java reflection or a script engine.

The pattern serves two purposes:

  1. Computed fields: Values that depend on the row data but aren't stored in the database (e.g., checking if a user is in a list)
  2. Server-side logic: Business rules that must run on the server (e.g., validating data, computing derived values)

Key design decisions:

  • Functions are registered in a Function database table, not hardcoded
  • Java functions are invoked via reflection on the AbstractFunctionParser subclass
  • Script functions (JavaScript, Lua, Python) are executed via JSR-223 script engines
  • Functions execute after the SQL query, with the row data as context
  • Version and tag constraints can restrict which requests can call which functions

The problem solved is allowing clients to request computed/derived values without a separate API endpoint. The function call is embedded in the same request that fetches the data.

Usage

Use this principle when:

  • API responses need computed fields that depend on query results
  • Server-side business logic needs to be invoked from the API
  • Functions should be configurable at runtime (not hardcoded)

Theoretical Basis

# Abstract algorithm (NOT real implementation):
def detect_and_execute_functions(response, request):
    for key, value in request.items():
        if is_function_call(key):  # key ends with "()"
            func_name, args = parse_function_call(key)
            metadata = FUNCTION_MAP.get(func_name)
            
            if metadata is None:
                raise UnknownFunctionError(func_name)
            
            if metadata.language == "java":
                result = invoke_java_method(func_name, args, response)
            else:
                result = invoke_script(metadata.language, func_name, args, response)
            
            # Substitute result into response
            response[key] = result

def invoke_java_method(name, arg_keys, current_row):
    method = find_method_on_parser(name, arg_types)
    arg_values = [current_row[k] for k in arg_keys]
    return method.invoke(parser, arg_values)

def invoke_script(language, name, args, current_row):
    executor = SCRIPT_EXECUTOR_MAP[language]
    return executor.execute(name, args, current_row)

Related Pages

Implemented By

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment