Qu

Data & I/O

HTTP requests

a genuine HTTP(S) GET over the real network, using Qu's `http_get(url)` builtin (§ HTTP fetch, see docs/qu-language-tour.md §21). `http_get` is GET-only, has a fixed 30-second connect+read timeout, and always returns the response body as

catalog/qu_http_get.qu

a plain string (lossily UTF-8 decoded) -- no headers, no status code, no POST, per its own documented v1 scope.

`https://example.com/` is the same target the language tour's own worked example uses: a stable, well-known, IANA-reserved domain that always serves a small, static 200 OK HTML page and is exceedingly unlikely to ever be flagged as suspicious traffic. This whole call is wrapped in try/catch: on a machine with no outbound network access (or a transient DNS/TLS/connection failure), `http_get` raises a clear EvalError naming the URL, which is caught and reported as an honest "network unavailable" result instead of crashing the script or faking a response.

What it exercises

Results

printed
GET https://example.com/ succeeded
response body length = 559 chars
body contains "Example Domain": true

The whole program

Runnable as it stands: qu run catalog/qu_http_get.qu

# qu_http_get.qu -- a genuine HTTP(S) GET over the real network, using

# Qu's `http_get(url)` builtin (§ HTTP fetch, see

# docs/qu-language-tour.md §21). `http_get` is GET-only, has a fixed

# 30-second connect+read timeout, and always returns the response body as

# a plain string (lossily UTF-8 decoded) -- no headers, no status code,

# no POST, per its own documented v1 scope.

#

# `https://example.com/` is the same target the language tour's own worked

# example uses: a stable, well-known, IANA-reserved domain that always

# serves a small, static 200 OK HTML page and is exceedingly unlikely to

# ever be flagged as suspicious traffic. This whole call is wrapped in

# try/catch: on a machine with no outbound network access (or a transient

# DNS/TLS/connection failure), `http_get` raises a clear EvalError naming

# the URL, which is caught and reported as an honest "network unavailable"

# result instead of crashing the script or faking a response.

#

# Constructs exercised (all real, verified-working builtins):

#   http_get(url)            -- a real GET request, 30s timeout, returns a Str body

#   length(str)               -- real byte/char count of the fetched body

#   try/catch                 -- graceful handling of the real network dependency


backend auto

url = "https://example.com/"

try
    body = http_get(url)
    print("GET {url} succeeded")
    print("response body length = {length(body)} chars")
    # `example.com` always serves a small static page containing this

    # exact phrase -- a real content check, not just "it didn't throw".

    # Qu has no dedicated substring-search builtin (grepped for

    # `index_of`/`str_contains`/similar -- zero hits), so `split` on the

    # target phrase does the job: more than one piece means it was found.

    parts = split(body, "Example Domain")
    contains_expected_text = length(parts) > 1
    print("body contains \"Example Domain\": {contains_expected_text}")
catch err
    print("http_get could not reach {url}: {err.message}")
    print("this is the expected, honest result in an environment with no outbound network access")
end