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¶
|
Return http_get(url, headers) -> (status, parsed JSON or None). |
|
Return http_post(url, headers, payload) -> (status, text or None). |
|
Resolve a host name such as "homeserver.local" to its address. |
|
Replace the host name in |
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).
payloadis 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,
hostis 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
urlby its address.For example http://homeserver.local:8123/x becomes http://192.168.1.10:8123/x (see
resolve_host).