Atom

http module

Make HTTP requests or serve requests through a listener.

Import it with 'use http'.

Start the local example server on port 18080 in another terminal before running this example.

Atom
use http
response = http.request({url = 'http://127.0.0.1:18080/'})
print(response.status)
Output
200

Requires libuv, OpenSSL and ATOM_WITH_HTTP. Client requests are synchronous and restricted to HTTP/HTTPS. The server is a synchronous HTTP/1.1 request loop over TCP, optionally with TLS. HTTPS authenticates the server and checks its name. Close a listener with net.close.

Request option Type and default Meaning
url Required nonempty string HTTP or HTTPS URL.
method HTTP token string, default GET Exact verb. HEAD omits request and response bodies.
headers Dictionary, default empty Names must be HTTP tokens. Values can be text, packed data or arrays of those values for repeats. Content-Length and Transfer-Encoding are reserved.
query Dictionary, default empty Appends percent-encoded keys and the display representations of values.
body Text or packed data, omitted by default Raw outgoing request body.
timeout Positive seconds or null for unlimited, default 30 seconds Total client timeout, rounded up to milliseconds.
redirects Nonnegative signed count, default zero Maximum followed redirects.
binary Boolean, default false Returns response body as packed bytes even when it is valid UTF-8.
max_body Nonnegative signed byte count, default 64 MiB Caps buffering when on_chunk is absent.
ca Nonempty CA bundle path, optional Overrides default trust and requires file access. Windows uses its root store when omitted.
on_chunk Optional function Called with each packed body chunk. Returning false stops the request with an error. The response's body is null.

Response headers use lowercase names, with an array for repetitions. Valid UTF-8 field/body data becomes a string unless binary body mode applies. Other bytes become packed data. The HTTP client and HTTP server examples connect over loopback.

Functions