network.fetch host allowlist), binding settings (settingsSchema + action.settingsChanged), client.networkFetch and fail-closed error display.
This example uses the host-brokered
client.networkFetch; that is for portability to the T2 (public sandbox) target. On the T1 (local dev) host, network.fetch is not wired yet — T1 is sandboxless Node, so do the network call directly: use const text = await (await fetch(url)).text(); instead of client.networkFetch({ url, method }) and remove the network.fetch permission from the manifest. Which capability works where: Capability APIs.1. Manifest: declare the permission and action
Update thepermissions and actions sections in manifest.json:
network.fetchis limited to the HTTPS hosts declared in the manifest; a request outsidewttr.ingetsCAPABILITY_DENIED.- The
settingsSchemafield appears in the app’s settings panel when the user assigns the action to a key.
2. Runtime: event → setting → network → screen
runtime.mjs:
- Reading settings:
getSettings(bindingId)returns the binding-specific persistent setting; when the user changes the setting,action.settingsChangedfires and you redraw. - Network:
networkFetch({ url, method })is validated by the host (HTTPS-only, host allowlist, bounded request/response). The response body is the bounded value returned by the host adapter; read it defensively. - Errors: on failure,
showError+ a short title; do not swallow exceptions, log them.
3. Try it
- Reload the project from the Developer window (since the manifest changed, remove and select it again if needed).
- On the Keys screen, assign the Hava action to a key.
- Enter Şehir (city) in the key’s settings panel (e.g.
Istanbul). The key updates likeIstanbul\n+29°C. - Pressing the key refreshes the data.
Where to go next
- Cache the temperature with
storageSetand show it instantly onwillAppear(see reference:storage.private). - Knob support: switch between cities with
controllers: ["Knob"]+action.dialRotate. - APIs with credentials:
network.fetchWithCredential— the raw token never returns to the plugin.
This project can be moved to the T2
sandbox-js target: the same SDK surface works with the Worker transport. For the public upload status, see Distribution status.