Use Serverless Transforms to process API responses
mainA transform script allows you to run code (python, ruby, php, or node) against a polled API response before it reaches your Liquid templates. This matches the hosted plugin service's behavior.
Implementation
- Create a file at
src/transform.{py,rb,php,js}. - Define a
run(input)function. The function receives the polled response as JSON viastdinand returns the new data object.
Configuration
- Enabled by default: Transforms run automatically if the file exists.
- Disable transforms: Set
transform_runtime: disabledin.trmnlp.yml. - Remote Daemon: To test against a real microVM daemon, set
serverless_daemon_url:in.trmnlp.ymland provide the token via the$TRMNL_SERVERLESS_DAEMON_API_KEYenvironment variable.
Language Detection
The language is determined by the file extension:
src/transform.py->pythonsrc/transform.rb->rubysrc/transform.js->nodesrc/transform.php->php
# src/transform.py
def run(input):
return {"items": [x["title"] for x in input["data"]]}# .trmnlp.yml
transform_runtime: enabled
serverless_daemon_url: https://transforms.your-team.exampleexport TRMNL_SERVERLESS_DAEMON_API_KEY=...
trmnlp serve