← index

[HTTP]Client

inherits Object · defined at net/http.qn:557

The convenience facade: class-side helpers for the common verbs. Kept thin so a future stateful client (base URL, default headers, pooling) can be an *instance* of this class without disturbing these.

Class methods

get:

GET url and return the [HTTP]Response; redirects are followed. The body arrives stream-backed — read it with .body.text / .json / .bytes, or stream it with .body.chunks.

use std:net/http;
var resp = [HTTP]Client.get:'https://example.org/';
resp.status;         "* e.g. 200
resp.body.text       "* the whole body as a String

net/http.qn:575

get: headers:

GET with extra request headers — #(name value) pairs.

[HTTP]Client.get:url headers:#( #('Accept' 'application/json') )

net/http.qn:580

post: body:

POST body to url. The body normalizes as [HTTP]Request body: does — a Map or List is JSON-encoded (Content-Type application/json), a String sends as its UTF-8 bytes, Bytes goes as-is, an [HTTP]Body is used unchanged.

resp = [HTTP]Client.post:'https://api.example.org/users' body:#{ 'name':'Quoin' }

net/http.qn:588

post: body: headers:

POST with extra request headers — #(name value) pairs.

net/http.qn:590

request:

A fresh [HTTP]Request builder for url — the escape hatch for custom verbs, headers, a body, insecure:, or redirect settings; finish the chain with .send.

resp = (([HTTP]Client.request:'https://example.org/x').method:'DELETE').send

net/http.qn:564