Backend-driven UI is older than most of our careers.
Perhaps older than most of us, full stop.
In the early web, the server told the browser exactly what to render, returning static HTML for a given URL. Layout and data flow sat server-side dictated by the PHP, Django, or Rails application. The client just rendered what it was told.
Gradually, in the 2000s, Ajax and jQuery introduced some client-side dynamism, but the front-end framework explosion of the 2010s placed nearly all the logic and rendering browser-side, with APIs and JSON replacing HTML.
Along came mobile apps in 2008.
These are one of the thickest clients imaginable, designed to run as a standalone computer program. Backend-driven UI can feel… alien. But this tool can be incredibly powerful when used judiciously.
Backend-driven UI, a.k.a. server-driven UI, is a little fuzzy to define. If your app connects to the internet, and displays some nicely-formatted JSON data, your UI is being driven by the backend.
(I’ll try to avoid being a pedantic jerk now). Your UI is backend-driven when the backend sends information about the structure of your screen as well as the content.
Backend-driven SwiftUI has 2 parts: a small, tightly-scoped DSL (domain-specific language), and a flexible parser that renders the content as views.
Confused? Good. It’ll become easy once you see the first example. The trick is balancing power, flexibility, and simplicity: nobody wants you to re-implement HTML from scratch.
Today we will:
Learn why you might want to introduce backend-driven UI
Define a minimal JSON-encoded DSL to render a static blog post.
Introduce layout composition and navigation to render a Netflix-style video feed (from the exact same base screen).
Build a fully-interactive form that posts multimedia data to an API.
Close with some sanity checks around when backend-driven UI is actually worthwhile.
Subscribe to Jacob’s Tech Tavern for free to get ludicrously in-depth articles on iOS, Swift, tech, & indie projects in your inbox every week.
Paid members get several benefits:
Access Elite Hacks, my exclusive advanced content 🌟
Read my free articles a month before anyone else 🚀
Grow your career with my Swift Concurrency course 🧵
Upgrade to read this article right now, or wait until November 24.
Keep reading with a 7-day free trial
Subscribe to Jacob’s Tech Tavern to keep reading this post and get 7 days of free access to the full post archives.