Skip to content

Add support for simple function calls in url header of the http processor#2179

Merged
amitu merged 5 commits intomainfrom
fix/function-call-in-http
Aug 20, 2025
Merged

Add support for simple function calls in url header of the http processor#2179
amitu merged 5 commits intomainfrom
fix/function-call-in-http

Conversation

@siddhantk232
Copy link
Copy Markdown
Contributor

@siddhantk232 siddhantk232 commented Aug 20, 2025

functions can now be used at url header of the http processor. This
allows the following code snippet to work:

-- import: fastn/processors

;; this could come from request-data processor for example
;; or some other reference, like:
;; -- string v: $some-other-reference
-- string v: foo

-- string x:
$processor$: processors.http
url: $some-func(v = $v)

-- string some-func(v):
string v:

"/api/" + v + "/"

Known issues

  • The function can't be a js function (a function definition with js:
    header) since we don't execute js on the server.

  • Typecheck between function params and args is not correct. While
    constructing the function call, we use the param's type for the arg's
    type. The right thing here is to resolve the reference and use the
    resolved type so that type check happens correctly. There's a TODO
    comment for this.

  • The function body supports simple expressions only and has been only
    tested with the + operator expression. To learn more about the full
    supported constructs, see the evalexpr crate.

functions can now be used at `url` header of the http processor. This
allows the following code snippet to work:

```ftd
-- import: fastn/processors

;; this could come from request-data processor for example
;; or some other reference, like:
;; -- string v: $some-other-reference
-- string v: foo

-- string x:
$processor$: processors.http
url: $some-func(v = $v)

-- string some-func(v):
string v:

"/api/" + v + "/"
```

** Known issues

- The function can't be a js function (a function definition with js:
  header) since we don't execute js on the server.

- Typecheck between function params and args is not correct. While
  constructing the function call, we use the param's type for the arg's
  type. The right thing here is to resolve the reference and use the
  resolved type so that type check happens correctly. There's a TODO
  comment for this.

- The function body supports simple expressions only and has been only
  tested with the + operator expression. To learn more about the full
  supported constructs, see the evalexpr crate.
If one of the subexpr for the + OP is different than the other, differ
to string concatenation by converting the number to string.
@siddhantk232 siddhantk232 requested a review from amitu August 20, 2025 07:14
@amitu amitu merged commit a28d703 into main Aug 20, 2025
1 check passed
@amitu amitu deleted the fix/function-call-in-http branch August 20, 2025 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants