Building Relay with SwiftUI
When we set out to build Relay, we knew we wanted to go fully native. SwiftUI had matured enough by 2025 that we felt confident building a production-grade macOS application with it.
This is a look at the decisions that shaped the app: why native, how the code is organized, and the one problem that took the most work to solve.
Why we went native
The decision to go native wasn't just about performance. It was about feel.
A REST client is a tool developers live in all day. You open it dozens of times, fire off a request, read the response, tweak a header, and send it again. Any delay in that loop is felt immediately. The app needs to be snappy, responsive, and deeply integrated with the operating system.
Most REST clients are built on web technology wrapped in a desktop shell. That approach works, and it makes cross-platform support easier. But it also means carrying a browser engine around to show a text field and a send button. We wanted an app that behaves like the rest of macOS, because that is where our users already are. We make the wider case for this in Why Native Apps Still Matter.
A modular architecture: networking apart from UI
We chose a modular architecture that separates the networking layer from the UI layer entirely. The HTTP engine knows nothing about SwiftUI, and the views know nothing about how a request is actually sent.
That separation pays off in two ways.
- The HTTP engine can be tested independently. Building a request, following redirects, decoding a response and timing it can all be covered by tests that never launch a window.
- The SwiftUI views stay thin and declarative. A view describes what the screen looks like for a given state. It does not contain networking logic that would be hard to reason about or reuse.
In practice the boundary is a small protocol. The UI asks for a request to be sent and gets a response back:
protocol HTTPEngine {
func send(_ request: RelayRequest) async throws -> RelayResponse
}
Everything behind that protocol can change without touching a single view, and every view can be previewed with a fake engine that returns canned responses.
The hard part: a fast response viewer
One of the biggest challenges was building a performant response viewer that could handle large JSON payloads.
Small responses are easy. The trouble starts when an endpoint returns several megabytes of JSON and the user expects to scroll through it as smoothly as a small one. Syntax highlighting makes it harder, because every key, string and number needs its own color.
The common shortcut is to embed a web view and let a JavaScript highlighter do the work. We decided against it. We ended up implementing a custom syntax highlighter using AttributedString rather than relying on a web view, which gave us much better scrolling performance.
Keeping the viewer native has other benefits too. Text selection, copy and paste, and find all behave the way they do everywhere else on the Mac, because they are the system's own text handling, not a reimplementation inside a web page.
What native bought us
The result is an app that launches in under a second, handles concurrent requests effortlessly, and feels like a true Mac citizen.
Being a good Mac citizen is a collection of small things:
- Standard menus and keyboard shortcuts that match system conventions.
- Windows and tabs that behave like every other Mac app.
- Light and dark appearance that follows the system setting.
- Low memory use, because there is no bundled browser engine.
None of these is a headline feature. Together they are the difference between a tool that feels like part of your machine and one that feels like a visitor.
What we'd tell another team
If you're considering SwiftUI for a serious macOS app, our experience is that it's ready, with one piece of advice: draw a hard line between your core logic and your views from the first day. SwiftUI rewards thin views. The more logic you keep outside them, the easier the app is to test, preview and change.
And when a system framework can do the job, as AttributedString did for our response viewer, try it before reaching for a web view. It took more work up front and gave us a better app.
You can see the result on the Relay page. If you have a macOS or iOS app of your own in mind, tell us about it.