libraryextensions/web/lib/Web.xtl
Web.xtl -- the facade of the web extension: HTTP serving, where the program is the request loop. axum serves on 127.0.0.1 in the background and queues each request; the program takes the next one, reads its parts, and replies. Import: "wb:" u_se< "Web" Run with xetal-x (xetal-x --ext DIR puts this directory on XETAL_PATH). Each signature line is written out by the binding macro (lib/Ffi.xtlm).
ˡs̲erve! : Num a => a -> Int
wb:s_erve! port: serve on 127.0.0.1 at the port (8470 is this repository's; 0 takes any free one); the port it serves on.
"s_erve! : int -> int" ᶠᶠⁱb̲ind< "web/serve"
ˡn̲ext! : Num a => a -> Char
wb:n_ext! seconds: wait up to that long for a request; "GET /path" (the method and path), or "none". A request taken before and not replied to is answered 500.
"n_ext! : float -> text" ᶠᶠⁱb̲ind< "web/next"
The request being answered
ˡm̲ethod : Unit -> Char
wb:m_ethod @: its method (GET, POST, ...).
"m_ethod : unit -> text" ᶠᶠⁱb̲ind< "web/method"
ˡp̲ath : Unit -> Char
wb:p_ath @: its path, without the query.
"p_ath : unit -> text" ᶠᶠⁱb̲ind< "web/path"
ˡq̲uery : Unit -> Char
wb:q_uery @: its query, as sent (still encoded).
"q_uery : unit -> text" ᶠᶠⁱb̲ind< "web/query"
ˡp̲aram : Char -> Char
wb:p_aram "name": a query or form field, decoded ("" when absent).
"p_aram : text -> text" ᶠᶠⁱb̲ind< "web/param"
ˡc̲ontent! : Char -> Int
wb:c_ontent! "text/csv": the reply's content type (else it is guessed from the body: SVG, HTML, JSON or plain text).
"c_ontent! : text -> int" ᶠᶠⁱb̲ind< "web/content"
ˡh̲eader! : Char -> Int
wb:h_eader! "Location: /": a header on the reply (a redirect's Location, Cache-Control, ...); how many the reply has.
"h_eader! : text -> int" ᶠᶠⁱb̲ind< "web/header"
ᶠᶠⁱb̲ind< expands to
ˡh̲eader! ← { a → pa ← a ⎕N̲PUT "ext:web/header?text" f̲loor f̲irst n̲umbers ⎕N̲GET "ext:web/header" }
ˡr̲eply! : Num a => a -> Char -> Int
status wb:r_eply! body: answer the request; the body's length in bytes.
"r_eply! : int text -> int" ᶠᶠⁱb̲ind< "web/reply"
ˡf̲iles! : Char -> Int
wb:f_iles! "dir": serve the files under dir (relative, no ..) directly, without the program; "" stops. How many files it holds.
"f_iles! : text -> int" ᶠᶠⁱb̲ind< "web/files"