httpclient

http_get/http_post for data sources, on top of a requests-like module.

On the board that is MicroPython’s requests; tests pass a fake.

Functions

make_http_get(requests[, timeout_s])

Return http_get(url, headers) -> (status, parsed JSON or None).

make_http_post(requests[, timeout_s])

Return http_post(url, headers, payload) -> (status, text or None).

resolve_host(host, port, getaddrinfo)

Resolve a host name such as "homeserver.local" to its address.

resolve_url(url, getaddrinfo)

Replace the host name in url by its address.

Module Contents

httpclient.make_http_get(requests, timeout_s=10)

Return http_get(url, headers) -> (status, parsed JSON or None).

httpclient.make_http_post(requests, timeout_s=15)

Return http_post(url, headers, payload) -> (status, text or None).

payload is sent as JSON. Any 2xx status, such as 201 Created, comes with the response text.

httpclient.resolve_host(host, port, getaddrinfo)

Resolve a host name such as “homeserver.local” to its address.

If it cannot be resolved, host is returned unchanged and connecting fails later. Resolving .local names via mDNS takes up to a second on the board, and MicroPython’s requests would do it again for every request.

httpclient.resolve_url(url, getaddrinfo)

Replace the host name in url by its address.

For example http://homeserver.local:8123/x becomes http://192.168.1.10:8123/x (see resolve_host).