sourceextensions/http/lib/Http.xtl
1⍝# Http.xtl -- the facade of the http extension: bounded HTTP GET, text
2⍝# from the web within size, time and redirect limits.
3⍝# Import: "ht:" u_se< "Http"
4⍝# Limits: XETAL_HTTP_MAX bytes (16 MiB), XETAL_HTTP_TIMEOUT seconds (30),
5⍝# 5 redirects; only http:// and https:// URLs. Downloads go under the
6⍝# working directory (or XETAL_HTTP_ROOT).
7⍝# Run with xetal-x (xetal-x --ext DIR puts this directory on XETAL_PATH).
8⍝# Each signature line is written out by the binding macro (lib/Ffi.xtlm).
9
10ᶠᶠⁱ⁼u̲se< "Ffi"
11
12⍝# ht:g_et url: the body as text; a status other than 2xx is an error.
13"g_et : text -> text" ᶠᶠⁱb̲ind< "http/get"
14⍝# ht:s_tatus @: the last response's status (0 if none came).
15"s_tatus : unit -> int" ᶠᶠⁱb̲ind< "http/status"
16⍝# ht:h_eader "content-type": a header of the last response ("" if absent).
17"h_eader : text -> text" ᶠᶠⁱb̲ind< "http/header"
18⍝# url ht:s_ave! "data/x.csv": the body into a file (whole, or not at all);
19⍝# how many bytes.
20"s_ave! : text text -> int" ᶠᶠⁱb̲ind< "http/save"
21
22⍝# The native package behind these functions.
23ˡpackage ← "http"
ᶠᶠⁱb̲ind< expands to
ˡh̲eader ← { a → pa ← a ⎕N̲PUT "ext:http/header?text" ⎕N̲GET "ext:http/header" }
ᶠᶠⁱb̲ind< expands to
ˡs̲ave! ← { a b → pa ← a ⎕N̲PUT "ext:http/save?text" pb ← b ⎕N̲PUT "ext:http/save?text" f̲loor f̲irst n̲umbers ⎕N̲GET "ext:http/save" }