import http
The http module starts asynchronous firmware HTTP requests. Scripts use it to send readings to APIs, pull configuration, or call webhooks.
Quick example
import http
def on_status(status, body):
print(status)
print(body)
def on_sent(status, body):
print("sent", status)
http.get("https://example.com/status", on_status)
http.post("https://example.com/data", {"ok": True}, on_sent)
importhttp
HTTP client native Berry module.
The http module starts asynchronous firmware HTTP requests. Scripts use it to send readings to APIs, pull configuration, or call webhooks.
API
2 available
http.get(url: str, callback: callback, certificate: str = None) -> any
http.get(url: str, callback: callback, certificate: str = None) -> anyStart an HTTP GET request.
Parameters
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
url |
str |
positional or keyword | Yes | Request URL. |
callback |
callback |
positional or keyword | Yes | Named global function to run when the request completes. Pass the function without quotes; the transpiler sends its name string to firmware. The callback receives status and body values. |
certificate |
str |
positional or keyword | No | Optional TLS certificate string accepted by firmware. |
Returns
any Native request status.
http.post(url: str, body: dict, callback: callback, certificate: str = None) -> any
http.post(url: str, body: dict, callback: callback, certificate: str = None) -> anyStart an HTTP POST request.
Parameters
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
url |
str |
positional or keyword | Yes | Request URL. |
body |
dict |
positional or keyword | Yes | Request body dict/list that Studio serializes to JSON, or a pre-serialized string. |
callback |
callback |
positional or keyword | Yes | Named global function to run when the request completes. Pass the function without quotes; the transpiler sends its name string to firmware. The callback receives status and body values. |
certificate |
str |
positional or keyword | No | Optional TLS certificate string accepted by firmware. |
Returns
any Native request status.