http
Canonical Import
fennel
(local http (require :http))Source Files
src/lua_http.cpp
What It Provides
http submits asynchronous HTTP client requests through the engine-owned HTTP client and exposes polling, callbacks, cancellation, headers, timeouts, redirects, and streaming response chunks.
API Summary
request(opts)submits a request and returns a numeric request id.opts.urlis required. Optional keys includemethod,body,headers,timeout-ms,connect-timeout-ms,delay-ms,follow-redirects,user-agent,callback/cb, andstream.poll([max-results])returns a 1-indexed table of completed responses and dispatches registered callbacks. A response hasid,ok,status,error,body, andheadersfields.cancel(id)asks the HTTP client to cancel a pending request and returns whether cancellation was accepted.- Streaming requests require
stream trueand a callback. The callback receives{ :chunk <bytes> }events and a final{ :done true }event.
Examples
fennel
(local http (require :http))
(local id (http.request {:url "https://example.com"
:method "GET"
:headers {:Accept "text/plain"}}))
(each [_ response (ipairs (http.poll))]
(when (= response.id id)
(print response.status)
(print response.body)))Errors and Platform Notes
request raises http.request requires a url when opts.url is empty. Streaming requests raise http.request with stream=true requires a callback when no callback is supplied. Callback delivery happens when the runtime dispatches/polls HTTP completions; non-callback completions are buffered until poll consumes them. Cancelled requests are reported with error set to "cancelled".
Related Modules
http_serverfor in-process HTTP routes and SSE.callbacksfor explicit callback dispatch in tests or command-line modules.
Aliases and Search Terms
Search terms: HTTP client, fetch, request, response, headers, streaming, redirects, curl.
