LEARN VOID

URLs and HTTP clients

Encode a query component, then choose buffered or streamed HTTP responses.

url-http.voidDownload source
use url

func entry(extra: i32) -> i32:
    var escaped = url.encode_component("a b")
    return (escaped.length as i32) + extra
Input 0Expected result 5

Encode one value

url.encode_component("a b") gives a%20b. Its five ASCII characters can be counted without opening a connection. Use url.parse for explicit HTTP(S) addresses and url.resolve for relative references. Both return typed errors.

Own requests and responses

Import net/http as http. http.open_client() returns a client or an error. A client owns its connection pool. Use get or send for a bounded buffered response. An HTTP error status such as 404 is still a response. Inspect its status separately from a DNS, TLS or timeout error.

Read incrementally

Use client.start and read chunks for large bodies. Consume and release each chunk to keep application memory bounded. Deterministically close transfers and clients. Cancellation cannot retract a request already received by the server.

Platform verification

The implementation supports HTTP/1.1, negotiated HTTP/2, TLS peer and hostname verification, proxy options and explicit client identity. Linux and macOS passed hosted suites. Windows Schannel P12 client authentication remains unresolved. Full HTTP acceptance is pending.

Try the operation

Set VOID_GUIDE_URL to a local HTTP server that returns status 200. The sample reads the received status. If lookup or transport fails, it returns the input fallback. Verification serves a loopback response for each execution.

read-status.voidDownload source
use os
use net/http as http

func entry(fallback: i32) -> i32:
    if os.env("VOID_GUIDE_URL") is Ok(var target):
        if http.get(target) is Ok(var response):
            return response.info.status
    return fallback
Input 0Expected result 200

Continue learning with Async tasks · File transfers.