httpclient ========== .. py:module:: httpclient .. autoapi-nested-parse:: 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 --------- .. autoapisummary:: httpclient.make_http_get httpclient.make_http_post httpclient.resolve_host httpclient.resolve_url Module Contents --------------- .. py:function:: make_http_get(requests, timeout_s=10) Return http_get(url, headers) -> (status, parsed JSON or None). .. py:function:: 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. .. py:function:: 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. .. py:function:: 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`).