Processing Text with remoteProcess

The remoteProcess function sends text from a Zesty.io content field to an external HTTPS endpoint for custom processing and returns the transformed result synchronously for rendering in the Web Engine. This enables dynamic transformations like converting Markdown to HTML, expanding shortcodes, or performing language-based processing (e.g., YAML to JSON).

Syntax

{{ content_field.remoteProcess(url) }}
  • Parameters:
    • content_field: The text-based content field (e.g., this.title, this.description) containing the text to process.
    • url: The HTTPS endpoint (as a string) that processes the text and returns the transformed result (e.g., "https://api.example.com/process").
  • Returns:
    • The processed text returned by the endpoint if successful.
    • In preview mode: [Error: <reason>] <original text> for errors (e.g., timeout, HTTP errors, invalid URL, loop usage).
    • In live mode: The original unprocessed text for errors, with issues logged server-side.
    • Error message if the URL is missing or the input is not a string.

Context

In the following examples, assume the content field this.title contains the text Hello, World. The remote endpoints are mock services designed to transform the input text (e.g., modifying the string or converting formats). The endpoint in the example transforms Hello -> Zesty. Note that the parsley endpoint will only hot swap the function call with the actual return of the third-party endpoint. For the example the endpoint returns a JSON response with the transformed text.

Usage Examples

Transform Text with a Remote Endpoint

Send the content of this.title to an endpoint that transforms the input text.

{{ this.title.remoteProcess("https://parsleyremotefunction-387953501748.us-central1.run.app") }}

Input: Hello, World (from this.title)
Output: {"result":"Zesty, World"}
Context: The endpoint receives Hello, World, processes it, and returns a JSON response with the transformed text.

Handle a Timeout in Preview Mode

Send the content of this.title to a slow endpoint that takes longer than 1 second to respond.

{{ this.title.remoteProcess("https://mock-slow-endpoint.example.com") }}

Output: [Error: Execution took too long] Hello, World
Context: The endpoint exceeds the 1-second timeout limit, triggering the guardrail to return the original text with an error message in preview mode.

Handle a Timeout in Live Mode

Same as above, but on a live URL.

{{ this.title.remoteProcess("https://mock-slow-endpoint.example.com") }}

Output: Hello, World
Context: The endpoint times out, returning the original text silently in live mode, with the error logged server-side for debugging.

Convert Markdown to HTML

Send a Markdown content field to an endpoint that converts it to HTML.

{{ this.content.remoteProcess("https://markdown-to-html.example.com") }}

Input: # Hello, World (from this.content)
Output: <h1>Hello, World</h1>
Context: The endpoint converts the Markdown input to HTML, which is then rendered in the Web Engine.

Error Cases

The following errors occur when remoteProcess is used incorrectly. Assume this.title contains Hello, World unless otherwise specified.

Missing URL Parameter

{{ this.title.remoteProcess() }}

Output (Preview): [Error: URL not defined] Hello, World
Output (Live): Hello, World
Cause: The url parameter is missing, so the function cannot process the text.

Usage in a Loop

{{each this.items as item}}
  {{ item.title.remoteProcess("https://parsleyremotefunction-387953501748.us-central1.run.app") }}
{{/each}}

Input: Sample Item Title (from item.title in the loop)
Output (Preview): [Error: Cannot use remoteProcess in loop statements] Sample Item Title
Output (Live): Sample Item Title
Cause: The function is blocked within {{each}} loops to prevent performance issues, returning the original text.

HTTP Error (e.g., 404 Not Found)

{{ this.title.remoteProcess("https://api.example.com/invalid") }}

Output (Preview): [Error: 404 - Something Went Wrong] Hello, World
Output (Live): Hello, World
Cause: The endpoint returns a 4xx error (e.g., resource not found), logged server-side.

Server Error (e.g., 500 Internal Server Error)

{{ this.title.remoteProcess("https://api.example.com/server-error") }}

Output (Preview): [Error: 500 - Server Error] Hello, World
Output (Live): Hello, World
Cause: The endpoint returns a 5xx error (e.g., server failure), logged server-side.

Limitations

  • Timeout: A strict 1-second timeout is enforced. If the endpoint does not respond within this time, the original text is returned (with an error message in preview mode).
  • Loop Restriction: Cannot be used within {{each}} loops to avoid performance degradation.
  • Error Handling: Errors (timeout, HTTP errors, invalid inputs) return the original text, with detailed messages in preview mode and silent logging in live mode.

Best Practices

  • Endpoint Design: Ensure the external endpoint responds within 1 second and returns the processed text in the response body (e.g., as JSON, plain text, or HTML).