Functions Routes
Functions routes provide endpoints for managing and executing custom functions within the NDF system.
Overview
The functions routes module handles the registration, execution, and management of custom functions that can be used to process nodes, perform calculations, or implement business logic.
Key Endpoints
Function Management
GET /functions- List all available functionsPOST /functions- Register new functionPUT /functions/{function_id}- Update function definitionDELETE /functions/{function_id}- Remove function
Function Execution
POST /functions/{function_id}/execute- Execute function with parametersPOST /functions/batch- Execute multiple functionsGET /functions/{function_id}/status- Get function execution status
Function Metadata
GET /functions/{function_id}- Get function detailsGET /functions/{function_id}/schema- Get function input/output schema
Usage Examples
Registering a Custom Function
import requests
function_def = {
"name": "calculate_molecular_weight",
"description": "Calculate molecular weight from chemical formula",
"parameters": {
"formula": {"type": "string", "required": True}
},
"code": "def calculate_molecular_weight(formula): ..."
}
response = requests.post("http://localhost:8000/functions", json=function_def)
Executing a Function
params = {"formula": "H2O"}
response = requests.post("http://localhost:8000/functions/calculate_molecular_weight/execute",
json=params)
result = response.json()
print(f"Molecular weight: {result['result']}")
Listing Available Functions
response = requests.get("http://localhost:8000/functions")
functions = response.json()
for func in functions:
print(f"- {func['name']}: {func['description']}")
Function Types
Functions can be categorized by type: - Node Processing: Functions that transform or analyze nodes - Calculation: Mathematical and computational functions - Validation: Functions that validate data structures - Utility: Helper functions for common operations
Error Handling
200- Success400- Invalid function definition or parameters404- Function not found422- Function execution error500- Internal server error
Dependencies
- Function execution engine
- Parameter validation
- Security sandboxing
- Result caching