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).

source · imports ffi: lib/Ffi.xtlm

ˡs̲erve! : Num a => a -> Int

function · line 13

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"
ᶠᶠⁱb̲ind< expands to
ˡs̲erve! ← { a →
  pa ← (f̲ormat r̲avel f̲loor a) ⎕N̲PUT "ext:web/serve?int=" c̲at f̲ormat s̲hape a
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:web/serve"
}
Used in: port, port

ˡn̲ext! : Num a => a -> Char

function · line 17

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"
ᶠᶠⁱb̲ind< expands to
ˡn̲ext! ← { a →
  pa ← (f̲ormat r̲avel f̲loat a) ⎕N̲PUT "ext:web/next?float=" c̲at f̲ormat s̲hape a
  ⎕N̲GET "ext:web/next"
}

The request being answered

ˡm̲ethod : Unit -> Char

function · line 21

wb:m_ethod @: its method (GET, POST, ...).

"m_ethod : unit -> text"        ᶠᶠⁱb̲ind< "web/method"
ᶠᶠⁱb̲ind< expands to
ˡm̲ethod ← { @ →
  ⎕N̲GET "ext:web/method"
}

ˡp̲ath : Unit -> Char

function · line 23

wb:p_ath @: its path, without the query.

"p_ath : unit -> text"          ᶠᶠⁱb̲ind< "web/path"
ᶠᶠⁱb̲ind< expands to
ˡp̲ath ← { @ →
  ⎕N̲GET "ext:web/path"
}

ˡq̲uery : Unit -> Char

function · line 25

wb:q_uery @: its query, as sent (still encoded).

"q_uery : unit -> text"         ᶠᶠⁱb̲ind< "web/query"
ᶠᶠⁱb̲ind< expands to
ˡq̲uery ← { @ →
  ⎕N̲GET "ext:web/query"
}

ˡb̲ody : Unit -> Char

function · line 27

wb:b_ody @: its body, as text.

"b_ody : unit -> text"          ᶠᶠⁱb̲ind< "web/body"
ᶠᶠⁱb̲ind< expands to
ˡb̲ody ← { @ →
  ⎕N̲GET "ext:web/body"
}

ˡp̲aram : Char -> Char

function · line 29

wb:p_aram "name": a query or form field, decoded ("" when absent).

"p_aram : text -> text"         ᶠᶠⁱb̲ind< "web/param"
ᶠᶠⁱb̲ind< expands to
ˡp̲aram ← { a →
  pa ← a ⎕N̲PUT "ext:web/param?text"
  ⎕N̲GET "ext:web/param"
}

ˡc̲ontent! : Char -> Int

function · line 32

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"
ᶠᶠⁱb̲ind< expands to
ˡc̲ontent! ← { a →
  pa ← a ⎕N̲PUT "ext:web/content?text"
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:web/content"
}

ˡh̲eader! : Char -> Int

function · line 35

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"
}
Used in: ᵘb̲ack

ˡr̲eply! : Num a => a -> Char -> Int

function · line 37

status wb:r_eply! body: answer the request; the body's length in bytes.

"r_eply! : int text -> int"     ᶠᶠⁱb̲ind< "web/reply"
ᶠᶠⁱb̲ind< expands to
ˡr̲eply! ← { a b →
  pa ← (f̲ormat r̲avel f̲loor a) ⎕N̲PUT "ext:web/reply?int=" c̲at f̲ormat s̲hape a
  pb ← b ⎕N̲PUT "ext:web/reply?text"
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:web/reply"
}

ˡf̲iles! : Char -> Int

function · line 40

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"
ᶠᶠⁱb̲ind< expands to
ˡf̲iles! ← { a →
  pa ← a ⎕N̲PUT "ext:web/files?text"
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:web/files"
}

ˡs̲top! : Unit -> Int

function · line 42

wb:s_top! @: stop serving; the port (0 if none was serving).

"s_top! : unit -> int"          ᶠᶠⁱb̲ind< "web/stop"
ᶠᶠⁱb̲ind< expands to
ˡs̲top! ← { @ →
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:web/stop"
}
Used in: port, port

ˡpackage : Char

value · line 45

The native package behind these functions.

ˡpackage ← "web"