Demonstrates how to call extern functions from user-defined Covenant functions.
Use kind="call" steps with the extern's snippet ID:
step id="s1" kind="call"
fn="http.get"
arg name="url" from="url"
as="response"
end
When your function calls an extern with effects, your function must declare those effects too:
snippet id="fetch.fetch_and_save" kind="fn"
effects
effect network // Required because we call http.get
effect filesystem // Required because we call fs.write_file
end
The compiler enforces this - you cannot call a function with effects you haven't declared.
Use kind="bind" to extract fields from struct results:
step id="s2" kind="bind"
field="body" of="response"
as="body"
end
Functions that call multiple externs with different error types return a union of all possible errors:
returns union
type="Unit"
type="HttpError"
type="IoError"
end
extern-bindings/- How to declare extern bindingsplatform-abstraction/- Cross-platform extern patterns