Servirtium for
LFE
No shipped package: vendor the binding's source at a release tag, with the native library from the release. Release v2.0.0-alpha.20.
- FFI mechanism
- shared C NIF (servirtium_nif OTP app), called directly. servirtium_lfe.lfe calls the shared servirtium_nif module directly. The one-file LFE module is compiled with lfec into its own OTP app directory next to the NIF app. Public names use underscores (base_url, last_kind) because a remote call to a hyphenated name does not resolve.
- Toolchain
- LFE with lfec/lfe on PATH, Erlang/OTP, and erl, erlc, cc and curl to build the NIF app (no minimum LFE or OTP version stated in the repo). Checked on current LFE from git master and OTP 29.
- Distribution
- Not on Hex. Compile one .lfe file with lfec next to a NIF app built from the release library
- Finding the library
- ERL_LIBS names the directory holding the servirtium_nif and servirtium_lfe app directories (code:priv_dir); the NIF finds libservirtium_vcr beside itself in priv/ via a $ORIGIN rpath. Do not set SERVIRTIUM_VCR_LIB or SERVIRTIUM_NIF_DIR.
- On GitHub
- lfe/ · README
Getting it
There is no published package for LFE. You vendor the binding's source into your project at the release tag v2.0.0-alpha.20 and take the native library from the same release.
- Build the shared native app from the release library (no Aether; needs erl, erlc, cc, curl).
VER=v2.0.0-alpha.20 RAW=https://raw.githubusercontent.com/servirtium/servirtium-vcr mkdir -p beam-libs curl -fsSL $RAW/$VER/erlang/build-nif-app.sh | SRC=$VER VER=$VER sh -s -- ./beam-libs - Compile the one LFE source file into its own OTP app directory. lfec prints one expected warning, 'redefining core function record/3'; do not rename the export.
mkdir -p beam-libs/servirtium_lfe/ebin curl -fsSL -o servirtium_lfe.lfe $RAW/$VER/lfe/src/servirtium_lfe.lfe curl -fsSL -o beam-libs/servirtium_lfe/ebin/servirtium_lfe.app $RAW/$VER/lfe/src/servirtium_lfe.app lfec -o beam-libs/servirtium_lfe/ebin servirtium_lfe.lfe rm servirtium_lfe.lfe - Put the apps on the code path and check it with the repo's consumer, which replays a canned tape.
export ERL_LIBS=$PWD/beam-libs mkdir -p tapes curl -fsSL -o tapes/single_get.md $RAW/$VER/lfe/example/tapes/single_get.md curl -fsSL -o consumer.lfe $RAW/$VER/lfe/example/consumer.lfe lfec -o . consumer.lfe lfe -noshell -pa . -eval '(consumer:main (list))' -eval '(halt 0)' # -> PASS ...
Record
Point your client at the VCR's base URL; the VCR forwards to the real service and hands back the real response. Nothing is written until you commit.
(let* ((rec (servirtium_lfe:record "tapes/climate_api.md" "https://climatedataapi.worldbank.org"))
(url (servirtium_lfe:base_url rec)))
;; point the system-under-test at url
(io:format "~s~n" (list (os:cmd (++ "curl -s " url "/api/v1/countries"))))
(servirtium_lfe:last_kind rec) ; 'ok
(servirtium_lfe:commit rec)) ; 'ok -- writes the tape. close on an uncommitted
; recording returns #(error Msg) and writes nothing;
; (servirtium_lfe:discard rec) drops it
Playback
The same tape, replayed with no network.
(let* ((vcr (servirtium_lfe:playback "tapes/climate_api.md"))
(url (servirtium_lfe:base_url vcr)))
;; point the system-under-test at url
(io:format "~s~n" (list (os:cmd (++ "curl -s " url "/api/v1/countries"))))
(servirtium_lfe:last_kind vcr) ; 'ok -- optional: assert a clean match
(servirtium_lfe:close vcr))
Idiomatic extras
Redact a secret at commit time
Redactions are calls on the running record server; the written tape is scrubbed, the live SUT sees real bytes.
(let ((rec (servirtium_lfe:record tape upstream)))
(servirtium_lfe:redact_header rec "Authorization")
(servirtium_lfe:redact_query_param rec "password")
(servirtium_lfe:redact_credentials rec)
;; ... drive the system under test ...
(servirtium_lfe:commit rec))
Volatile value that round-trips
Options go in before the server starts; a bad rule fails the start. A response token must be bound on playback.
(let ((vcr (servirtium_lfe:playback_with "tapes/create_case.md"
(list (tuple 'volatile_rule "response headers" "Date: {{serverDate}}")
(tuple 'bind "serverDate" "Tue, 24 Nov 2026 00:00:00 GMT")))))
(io:format "~s" (list (servirtium_lfe:volatile_report vcr)))
(servirtium_lfe:close vcr))
Playback range
Replay only interactions 4..6 of a tape (0-based, inclusive); raises #(servirtium Reason) if refused.
(let ((vcr (servirtium_lfe:playback "tapes/journey.md")))
(servirtium_lfe:set_playback_range vcr 4 6))
Gotchas
- Public API names use underscores (servirtium_lfe:base_url, last_kind, tape_length); internal helpers are hyphenated.
- record is an LFE core form, so the exported record/2,3 delegate to an internal open-recording; the expected lfec warning 'redefining core function record/3' cannot be suppressed.
- undef on servirtium_lfe:... means the .beam is not compiled or ERL_LIBS does not name beam-libs; undef on servirtium_nif:... or bad_name means the NIF app is missing from the same place.
- lfec: command not found is a missing LFE install (rebar3_lfe or a release), not a Servirtium problem.
- close on a record that was neither committed nor discarded returns #(error Msg) and writes no tape.
Prompt for your coding agent
Paste this into Claude, Codex, Gemini or any coding agent, in your LFE project. It wraps one of your existing integration tests with Servirtium. The general prompt has a slot for the language instead.
Hey Gemini or Claude or Codex,
I want a test in this LFE project to run without calling a real web service every time. Use Servirtium (https://servirtium.dev), which records HTTP conversations as readable Markdown "tapes" and replays them. Do these steps in order and tell me what you did at each one.
1. Find an existing integration test in this project that calls a web service as a side effect of what it is testing. Prefer one that is slow, flaky, or needs credentials or network because of that call. Tell me which test you chose and why.
2. Add the Servirtium binding for LFE. Follow https://servirtium.dev/languages/lfe/ exactly. Servirtium ships no package for this language. Vendor the binding's source into the project at the release tag v2.0.0-alpha.20 and put the native library from the same release where the page says: Not on Hex. Compile one .lfe file with lfec next to a NIF app built from the release library.
Toolchain and minimum version: LFE with lfec/lfe on PATH, Erlang/OTP, and erl, erlc, cc and curl to build the NIF app (no minimum LFE or OTP version stated in the repo). Checked on current LFE from git master and OTP 29..
How the binding finds the native library: ERL_LIBS names the directory holding the servirtium_nif and servirtium_lfe app directories (code:priv_dir); the NIF finds libservirtium_vcr beside itself in priv/ via a $ORIGIN rpath. Do not set SERVIRTIUM_VCR_LIB or SERVIRTIUM_NIF_DIR.
3. Route that test's HTTP client to the Servirtium VCR's base URL instead of the real service, using the idiomatic LFE way of setting a base URL or HTTP client. The VCR starts on its own port (use port 0, so it picks a free one) and gives you its base URL; give that URL to the client and never hard-code a port.
4. Run the test once in record mode against the real service. Commit the recording when the test passes and discard it when the test fails: a record VCR that is closed without a commit or a discard writes no tape and raises an error. Use redact_credentials (the spelling for LFE is on the page) so secrets become numbered tokens, and remove volatile request headers such as User-Agent and Date from the tape so playback does not depend on them.
5. Keep the tape beside the test as readable Markdown, in version control. Open it and check there are no secrets or personal data in it before committing.
6. Make the test play back by default, with an explicit switch (for example an environment variable such as SERVIRTIUM_RECORD=1) that re-records.
7. Prove it works offline: make the real service unreachable (network off, or a wrong host) and show the test still passes in playback.
Traps to avoid:
- A record VCR needs Commit() or Discard(); closing it without either writes nothing and raises.
- The VCR runs in your test process on its own port; the system under test must use the VCR's base URL, not the real one.
- Public API names use underscores (servirtium_lfe:base_url, last_kind, tape_length); internal helpers are hyphenated.
- record is an LFE core form, so the exported record/2,3 delegate to an internal open-recording; the expected lfec warning 'redefining core function record/3' cannot be suppressed.
- undef on servirtium_lfe:... means the .beam is not compiled or ERL_LIBS does not name beam-libs; undef on servirtium_nif:... or bad_name means the NIF app is missing from the same place.
- lfec: command not found is a missing LFE install (rebar3_lfe or a release), not a Servirtium problem.
- close on a record that was neither committed nor discarded returns #(error Msg) and writes no tape.
References:
- This language's page: https://servirtium.dev/languages/lfe/
- The binding's directory: https://github.com/servirtium/servirtium-vcr/tree/main/lfe
- Concepts, features and every language's quick start: https://servirtium.dev/llms-full.txt (index: https://servirtium.dev/llms.txt)
How these snippets were checked
On cachyos (linux-x86_64, OTP 29, LFE built from git master with make compile; no LFE on the Mac): ran the Getting it steps (build-nif-app.sh from the tag with SRC=VER, lfec of servirtium_lfe.lfe and consumer.lfe, ERL_LIBS): PASS[discovery]. Also ran an LFE module that records /ok from a local upstream, commit returns ok, replays it (last_kind ok), and shows close without commit returns #(error ...) with no tape written. The redact and playback_with extras and the range snippet were not run; names checked against src/servirtium_lfe.lfe.
They mirror these files in the repository:
See also the feature reference, llms.txt and the lfe/ directory.