Networking
Kog apps talk to the network with the same globals you already know from the
web — fetch, WebSocket, WiFi, and a Kog-native socket API — available
with no import:
const res = await fetch('https://api.example.com/status');
const status = await res.json();
No import { fetch }, no setup. The runtime installs these globals before your
app runs, on every target: the ESP32 device, the desktop simulator, and the
in-browser playground.
One surface, three targets
The API is identical everywhere; only what's underneath changes.
| ESP32 device | Desktop simulator | Web playground | |
|---|---|---|---|
| fetch / WebSocket | native HTTP/WS client | host sockets | the browser's own (CORS applies) |
| TCPSocket / UDPSocket / TCPServer | lwIP | host sockets | not available — throws a clear error |
| WiFi | real join | always-connected emulation | always-connected emulation |
This means you can prototype a fetch-driven dashboard in the playground, run it
in the simulator, and flash it to a board — no code changes.
Honest about the edges
Kog is a microcontroller runtime, not a browser, so the surface is narrowed to
what native actually delivers. The narrowings are deliberate and documented:
bodies are buffered (no ReadableStream), there's no Blob/FormData, sockets
deliver ArrayBuffer, and Wi-Fi is emulated off-device. The full list is in the
API reference divergences.
Two edges worth knowing up front:
- CORS is real in the web playground. There,
fetchandWebSocketare the browser's, so cross-origin calls obey the same-origin policy. On a device there is no CORS. See the fetch guide. - Raw sockets don't exist in a browser.
TCPSocket/UDPSocket/TCPServerthrow a helpful error in the playground; run them on a device or the desktop simulator.
Where to go next
- fetch — HTTP requests, JSON, timeouts, errors, CORS.
- WebSocket — live bidirectional streams.
- Sockets — raw TCP/UDP and running a server on-device.
- Wi-Fi — connecting, and baking credentials in at flash time.
- API reference — every global, every method, every divergence.