What is the recommended way (or is there a way) to make web requests/api calls etc. within hoot.
I was hoping to make a get request in my app, and then parse the returned json. My initial idea was to use the guile web modules, but those don’t seem to be included in hoot yet.
Thanks for the help!
There is nothing built-in, currently. One option would be to use (hoot ffi) to write a binding for fetch.
1 Like
This took me a bit of playing around to figure out so I figured I’d add an example of how I was able to implement a fetch (error handling left as an exercise for the reader, and future me)
On the host:
window.addEventListener("load", async () => {
try {
const [proc] = await Scheme.load_main("main.wasm", {
user_imports: {
json: {
stringify: (resource) => JSON.stringify(resource),
},
window: {
fetch: async (resource) => {
const response = await fetch(resource);
const result = await response.json();
return result;
}
},
});
proc.call_async();
} catch(e) {
if(e instanceof WebAssembly.CompileError) {
document.getElementById("wasm-error").hidden = false;
}
throw e;
}
});
In hoot:
(use-modules
(fibers promises)
(hoot ffi))
(define-foreign stringify
"json" "stringify"
(ref extern) -> (ref string))
(define-foreign fetch
"window" "fetch"
(ref string) -> (ref extern))
(lambda (resolved rejected)
(call-with-async-result
resolved rejected
(lambda ()
(let* ((result (await (fetch "${JSON-URL}")))
(result-string (stringify result)))
(format #t "~a" result-string)
2 Likes
kryptec
September 7, 2026, 11:10pm
4
Well a year later I finally got around to making this work.
I was able to use your hints/code to fetch the wikimedia picture of the day for my puzzle game.
I’m pretty sure I didn’t do this in the best way, but it’s working! Thanks for the help!
https://puzzled.do-ocracy.ca/
2 Likes
alanz
September 8, 2026, 9:03pm
5
Its great to see this back again. I can see some idle time disappearing for me
1 Like
kryptec
September 9, 2026, 7:12am
6
Happy to see it getting some use!