1
1
Fork 0
forked from fun/fun

Added HTTP library http.fun and an examples script. (0.42.2)

This commit is contained in:
Johannes Findeisen 2026-07-04 19:54:07 +02:00
commit 302caf3ce7
3 changed files with 403 additions and 0 deletions

View file

@ -0,0 +1,31 @@
/*
* Example: Simple HTTP server using stdlib net/http_server
*
* Run:
* $ fun examples/blocking/net/http.fun
*
* It will serve files from the ./web directory on http://127.0.0.1:8080
*
* Test with curl in another terminal:
* $ curl -v http://127.0.0.1:8080/
* $ curl -v http://127.0.0.1:8080/index.html
*
* You can also place a .fun script in ./web (e.g. hello.fun) and call it:
* $ curl -v 'http://127.0.0.1:8080/hello.fun?name=Fun'
*/
#include <net/http_server.fun>
// Configure
PORT = 8080
DOC_ROOT = "./examples/data/htdocs/"
print("Starting simple HTTP server example…")
print("Serving '" + DOC_ROOT + "' on http://127.0.0.1:" + to_string(PORT))
print("Press Ctrl+C to stop.")
srv = HTTPServer(PORT)
srv.set_htdocs(DOC_ROOT)
// Start (blocking loop)
srv.start()