Types
HttpMethod
HttpResponse
HttpResponse type {
status: Int,
headers: Map,
body: Str | Bytes | Map
}
HTTP response returned from request functions.
Example
response ::hot::http/get("https://api.example.com/users/1")
response.status // 200
response.headers // {"content-type": "application/json", ...}
response.body // {"id": 1, "name": "Alice"}
StreamFormat
StreamingHttpResponse
StreamingHttpResponse type {
status: Int,
headers: Map,
body: Any
}
HTTP response with a streaming body iterator.
Fields
status- HTTP status codeheaders- Response headersbody- An iterator that yields chunks from the response stream
Functions
delete
fn (url: Str): HttpResponse
Send an HTTP DELETE request to url.
Example
response ::hot::http/delete("https://api.example.com/users/1")
// response.status = 204
get
fn (url: Str): HttpResponse
Send an HTTP GET request to url.
Example
response ::hot::http/get("https://api.example.com/users/1")
// response.status = 200
// response.body = {"id": 1, "name": "Alice"}
get-stream
fn (url: Str, format: StreamFormat): StreamingHttpResponse
fn (url: Str): StreamingHttpResponse
Make a streaming HTTP GET request.
Example
response get-stream("https://api.example.com/events", "sse")
for-each(response.body, fn (event) {
print(event.data)
})
is-ok-response
fn (response: HttpResponse): Bool
Return true if the HTTP response status is between 200 and 299.
Example
response ::hot::http/get("https://api.example.com/data")
if(::hot::http/is-ok-response(response), response.body, err("Request failed"))
patch
fn (url: Str, body: Any): HttpResponse
Send an HTTP PATCH request to url with body.
Example
response ::hot::http/patch("https://api.example.com/users/1", {"email": "new@example.com"})
post
fn (url: Str, body: Any): HttpResponse
Send an HTTP POST request to url with body.
Example
response ::hot::http/post("https://api.example.com/users", {"name": "Bob"})
// response.status = 201
post-stream
fn (url: Str, body: Any, headers: Map, format: StreamFormat): StreamingHttpResponse
fn (url: Str, body: Any, headers: Map): StreamingHttpResponse
fn (url: Str, body: Any): StreamingHttpResponse
Make a streaming HTTP POST request.
Example
response post-stream("https://api.example.com/stream", {query: "test"}, {}, "ndjson")
for-each(response.body, fn (item) {
print(item)
})
put
fn (url: Str, body: Any): HttpResponse
Send an HTTP PUT request to url with body.
Example
response ::hot::http/put("https://api.example.com/users/1", {"name": "Updated"})
request
fn (method: HttpMethod, url: Str, headers: Map, body: Any): HttpResponse
Perform an HTTP request with the given method, url, headers, and body.
Example
response ::hot::http/request(
"POST",
"https://api.example.com/data",
{"Content-Type": "application/json"},
{"name": "Alice"}
)
// response.status = 201
request-stream
fn (method: HttpMethod, url: Str, headers: Map, body: Any, format: StreamFormat): StreamingHttpResponse
fn (method: HttpMethod, url: Str, headers: Map, body: Any): StreamingHttpResponse
Make a streaming HTTP request that returns an iterator for the body.
Use this for Server-Sent Events (SSE), NDJSON streams, or any response you want to process incrementally.
Formats
"sse"- Server-Sent Events, parses event/data/id fields"ndjson"- Newline-delimited JSON"raw"- Raw chunks as strings or bytes
Example
response request-stream("GET", "https://api.example.com/events", {}, "", "sse")
for-each(response.body, fn (event) {
print(event.data)
})