MetaCall Express FaaS REPL Example
An example of building a FaaS server with NodeJS and Express, which implements a REPL protocol, suitable for projects like IPython / Jupyter where the exec
constraints make embedding MetaCall difficult. This offers a multi-language REPL protocol and an inline module loader in order to allow loading and calling functions between languages in the REPL.
-
Install MetaCall:
curl -sL https://raw.githubusercontent.com/metacall/install/master/install.sh | sh
-
Install dependencies:
metacall npm install
-
In a terminal, run:
metacall server.js
-
For testing with CURL:
a) Inline Module Loading:
curl -X POST -H 'Content-Type: application/json' localhost:7777/eval/node -d '{"data": "module.exports = { f: () => 4 }"}'
b) REPL:
curl -X POST -H 'Content-Type: application/json' localhost:7777/repl/node -d '{"data": "5555555554\n"}'
c) Calling the function
f
in the REPL, previously loaded by stepa
:curl -X POST -H 'Content-Type: application/json' localhost:7777/repl/node -d '{"data": "require(\"metacall\").metacall(\"f\")\n"}'
-
In order to close it:
curl localhost:7777/shutdown