Web · real, tested code

Build a Minimal HTTP Server in Larzscript

Answer a real TCP connection with a real HTTP response - the raw socket_listen/accept/read/write builtins under the tcp package's serve() helper.

tcp.serve(port, handler) loops accept -> read -> your handler -> write forever, one connection at a time (this is a single-threaded interpreter, so no OS-thread concurrency) - genuinely a server that answers curl, not a simulation of one.

Code

import "tcp" as tcp

let body = "hello from Larzscript"
let response = "HTTP/1.1 200 OK\r\nContent-Length: " + str(len(body)) + "\r\n\r\n" + body
print(response)
# tcp.serve(8080, fn(request) { return response })  # uncomment to actually listen
Output
HTTP/1.1 200 OK
Content-Length: 21

hello from Larzscript