Want a fast desktop app without Electron’s weight? Pair Bun with a WebView and talk over a localhost JSON API—simple, fast, and local-first.
What this is
The pattern: run a tiny Bun server that exposes a JSON API, then point a WebView at it for the UI. Your frontend calls fetch() to hit the local endpoints.
Simon Willison recently highlighted this approach for quick, reliable desktop tools and prototypes—no heavyweight bundlers needed. Source: Bun + WebView JSON API.
Why it matters
- Speed: Bun’s server is extremely fast, and WebView boots quicker than full Chromium stacks.
- Local-first: Keep data and models on-device for privacy and offline use.
- Simplicity: Clear separation—UI in WebView, logic in a JSON API—eases testing and iteration.
How it works (3 steps)
- Start a Bun server (bun.serve) on 127.0.0.1:PORT with routes like /api/* that return JSON.
- Launch a WebView that loads http://127.0.0.1:PORT. Serve static assets or inline a minimal UI.
- From the UI, call fetch(‘/api/task’) to trigger local operations—no cloud required.
Security essentials for localhost bridges
- Bind to 127.0.0.1 only. Do not expose to the LAN.
- Use a random high port per run and pass it securely to the WebView.
- Issue a one-time CSRF token; require it on all state-changing requests.
- Set strict CORS and an allowlist for the WebView origin.
- Prefer POST for mutating actions and validate inputs rigorously.
- Log locally and surface errors in the UI for fast debugging.
Great use cases
- Local LLM helpers and prompt tools with on-disk models.
- Privacy-first file organizers, batch converters, and scrapers.
- Data viewers for SQLite/Parquet/CSV that never leave your machine.
- Internal utilities and admin consoles for trusted teams.
References
Deep dive and example: Simon Willison on the Bun + WebView JSON API pattern.
Bun HTTP server docs: bun.sh/docs/api/http.
Takeaway
For small, snappy desktop tools, Bun + WebView + a localhost JSON API is a clean, fast pattern. Start with bun.serve, lock it to 127.0.0.1, and build iteratively.
Like insights like this? Subscribe to our newsletter for weekly, no-fluff AI and dev patterns: theainuggets.com/newsletter.

