wfn Web Function First draft
SPEC EXTENSION

Pipelining

A standardized, flexible, and stateless contract for executing a sequence of function calls where the input of a subsequent call depends on the output of previous calls.

Introduction

This specification defines how a Web Function package can signal that it supports function pipelining, and how clients can use this feature to execute a sequence of function calls where the input of a subsequent call depends on the output of previous calls.

Discovery

A package supports pipelining if it includes a pipeline_url in its definition. Clients send the pipeline array to this URL via POST.

Referencing

Clients reference results from earlier steps using JSONPath syntax where the root $ represents the array of results gathered in the current pipeline.

Example syntax

$[index]['path']['to']['key']

Escaping

If an argument value is a string that must literally start with a $ (and should not be interpreted as a JSONPath), it must be escaped with a backslash: \$. For example "$100" is treated as an invalid JSONPath. "\$100" is interpreted as the literal string "$100".

Execution logic

A pipeline request is an array of invocations. Each invocation is an object with the following keys:

  • url: The URL to invoke.
  • headers: The headers to send with the request.
  • body: The body to send with the request.

Example pipeline request

[
  {
    "url": "https://auth.example.com/find-user",
    "headers": {},
    "body": { "email": "dev@example.com" }
  },
  {
    "url": "https://stats.example.com/get-user-stats",
    "headers": {},
    "body": {
      "user_id": "$[0]['id']",
      "category": "performance"
    }
  }
]

Processing rules

  • The server executes the first invocation and stores the result at index 0.

  • Then for each subsequent invocation

    • The server scans arguments for strings starting with $.

    • If a string starts with \$, the \ is removed and the rest is treated as a literal.

    • If it starts with $ (and is not escaped), the server evaluates the JSONPath against the results array gathered so far.

    • The server replaces the reference with the retrieved value.

  • If any step returns an error, the pipeline terminates and returns the partial array of results as a JSON array, where each index matches the corresponding call in the request up to the error.

  • Upon successful completion of all steps, the server returns the full array of results as a JSON array, where each index matches the corresponding call in the request.