<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ritesh Khore on Medium]]></title>
        <description><![CDATA[Stories by Ritesh Khore on Medium]]></description>
        <link>https://medium.com/@riteshkhore?source=rss-986452d9db79------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*S7Zw8S6sMgtz7k2H6wJciA.jpeg</url>
            <title>Stories by Ritesh Khore on Medium</title>
            <link>https://medium.com/@riteshkhore?source=rss-986452d9db79------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 04:33:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@riteshkhore/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building a Type-Safe Strapi Swift SDK - A Junior Developer’s Journey With AI as a Mentor]]></title>
            <link>https://medium.com/@riteshkhore/building-a-type-safe-strapi-swift-sdk-a-junior-developers-journey-with-ai-as-a-mentor-69d28db277f4?source=rss-986452d9db79------2</link>
            <guid isPermaLink="false">https://medium.com/p/69d28db277f4</guid>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[swift-package-manager]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[strapi]]></category>
            <dc:creator><![CDATA[Ritesh Khore]]></dc:creator>
            <pubDate>Sun, 22 Feb 2026 16:39:01 GMT</pubDate>
            <atom:updated>2026-02-22T16:39:01.917Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Building a Type-Safe Strapi Swift SDK— A Junior Developer’s Journey With AI as a Mentor</strong></h3><h4>There’s a specific kind of imposter syndrome that hits when you’re a junior developer staring at a concept you’ve never heard of, wondering if you’re even supposed to be here. This article is for everyone who’s felt that and built something anyway.</h4><p>I built an open source Swift package.</p><h3><strong>A Honest Confession First</strong></h3><p>Let me be upfront about something before we go any further.</p><p>When developers write articles about open source packages they’ve built, there’s often an implied narrative the experienced engineer who sat down, designed the perfect architecture, and shipped it confidently. That’s not my story.</p><p>I’m Ritesh. I have ~2 years of iOS development experience. I’m still what many would call a junior developer.</p><p>When I started this project I didn’t know what @resultBuilder was. I didn’t know what recursive encoding meant. I didn’t fully understand the difference between value types and reference types in the context of Swift concurrency.</p><p>I built this package with a help from AI Claude and ChatGPT were my mentors, my rubber duck and my pair programming partner throughout this entire journey. I’m sharing this because I think the developer community needs more honest stories. Not the polished “I built this in a weekend” posts, but the real ones the dead ends, the confusion, the moments of “why is this not working?” and the gradual, sometimes painful process of understanding.</p><p>This is that story.</p><h3>What is Strapi?</h3><p>If you haven’t heard of Strapi before — it’s an open source headless CMS (Content Management System) that lets you build and manage your backend API without writing a traditional server from scratch.</p><p>Instead of building REST endpoints manually, you define your content types like Articles, Users, Products and Strapi automatically generates a full REST (and GraphQL) API for them. You get CRUD operations, user management, media uploads, and role-based permissions out of the box.</p><p>It’s particularly popular with frontend and mobile developers because it lets you focus on building your app rather than maintaining a backend. Think of it as a backend that gets out of your way.</p><p>For a Swift developer building a content-driven app a blog, an e-commerce app, a social platform Strapi is an attractive choice. Until you have to query it.</p><h3><strong>The Itch I Had to Scratch</strong></h3><p>I was building a Swift app backed by Strapi v5. Things started simply enough a couple of API calls, some URLSession code, and a few Codable models. But as the app grew, I kept running into the same frustration over and over again.</p><p>Strapi’s REST API uses a deeply nested bracket notation for filtering, sorting, and populating relations. A query that finds published articles in the “swift” or “ios” category, populated with their author’s name and avatar, sorted by date, paginated looks like this in the URL:</p><pre>/articles?filters[$and][0][status][$eq]=published<br>&amp;filters[$and][1][$or][0][category][$eq]=swift<br>&amp;filters[$and][1][$or][1][category][$eq]=ios<br>&amp;populate[author][fields][0]=name<br>&amp;populate[author][fields][1]=avatar<br>&amp;sort[0]=publishedAt:desc<br>&amp;pagination[page]=1<br>&amp;pagination[pageSize]=20</pre><p>And I was building this. By hand. In Swift. With string concatenation.</p><p>Every time I needed a new query I was copying, pasting, and praying I didn’t introduce a typo. The worst part?</p><p>A typo in a filter key doesn’t throw an error Strapi just silently ignores the malformed parameter and returns unfiltered results.</p><p>I was frustrated. Not just with Strapi with myself. I felt like there had to be a better way and I just didn’t know what it was yet.</p><h3><strong>The Goal — And the Fear</strong></h3><p>I wanted something that would let me write that query like this:</p><pre>let response = try await client.execute(<br>  StrapiRequest&lt;[ArticleDTO]&gt;(<br>    endpoint: &quot;/articles&quot;,<br>    query: StrapiQuery()<br>      .filters {<br>        $0.and {<br>          $0.equals(&quot;status&quot;, &quot;published&quot;)<br>          $0.or {<br>            $0.equals(&quot;category&quot;, &quot;swift&quot;)<br>            $0.equals(&quot;category&quot;, &quot;ios&quot;)<br>          }<br>        }<br>      }<br>      .populate(&quot;author&quot;) {<br>        $0.fields(&quot;name&quot;, &quot;avatar&quot;)<br>      }<br>      .sort(&quot;publishedAt&quot;, .desc)<br>      .page(1, size: 20)<br>  )<br>)</pre><p>Type-safe. Readable. Compiler-checked.</p><p>But here’s the thing I had no idea how to build something like that. I’d seen SwiftUI. I knew it used some kind of “builder” syntax. But how? I didn’t have the vocabulary to even search for it properly. So I started asking questions and learning as I went.</p><h3><strong>Part 1 — Learning While Building</strong></h3><p>That’s when I first heard the term @resultBuilder.</p><p>It’s the mechanism SwiftUI uses under the hood. You list things inside a closure and Swift automatically collects them into an array. The syntax I was imagining looked exactly like this:</p><pre>.filters {<br>  .and {<br>    .equals(&quot;category&quot;, &quot;shoes&quot;)<br>      .equals(&quot;category&quot;, &quot;bags&quot;)<br>  }<br>}</pre><p>No $0, no prefixes. Clean as SwiftUI. I was excited — and briefly proud of how elegant it looked.</p><p>Then I tried to compile it.</p><blockquote>Cannot infer contextual base in reference to member ‘and’</blockquote><p>I stared at this error for a long time. The problem, it turns out, is a Swift compiler limitation it can’t infer the type of the <em>first</em> expression in a @resultBuilder block from the return type alone. Leading dot syntax only work after the type is already established by an explicit reference.</p><p>The workaround was to prefix the first line with the explicit type name:</p><pre>.filters {<br>  FilterNode.and {<br>    .equals(...)<br>    // ← users would have to write this<br>  }<br>}</pre><p>That felt wrong. I was building this for developers who shouldn’t need to know about FilterNode. Exposing internal types in the public API isn’t good design. I tried wrapping things in a Filter namespace. I tried different approaches. Each one had some friction.</p><p>Eventually, after a lot of back and forth, I was introduced to a pattern I hadn’t seen used this way before inout parameters with mutating methods.</p><h3><strong>Part 2 — The Breakthrough I Didn’t Expect</strong></h3><p>The inout approach looked like this:</p><pre>public struct FilterQueryBuilder: Sendable {<br>    private(set) var nodes: [FilterNode] = []<br><br>    public mutating func and(_ block: (inout FilterQueryBuilder) -&gt; Void) {<br>        var child = FilterQueryBuilder()<br>        block(&amp;child)<br>        nodes.append(.and(child.nodes))<br>    }<br>}</pre><p>And the DSL:</p><pre>.filters {<br>    $0.and {<br>        $0.equals(&quot;category&quot;, &quot;shoes&quot;)<br>        $0.equals(&quot;category&quot;, &quot;bags&quot;)<br>    }<br>}</pre><p>Honestly? My first reaction was disappointment. I wanted the clean SwiftUI style syntax without $0. But the more I thought about it, the more it made sense.</p><p>@resultBuilder is designed for declarative list construction where order and accumulation don’t matter much like SwiftUI views. Filters are <strong>imperative </strong>you’re explicitly accumulating nodes in a specific structure. inout with mutating is the correct pattern for that use case.</p><p>And $0 is already familiar to any Swift developer who’s used closures. Autocomplete works perfectly on it. It’s not beautiful in the abstract — but it’s <strong>practical</strong>, and that matters more.</p><p>That was a real lesson for me. Sometimes the elegant looking solution isn’t the right one. Experience helps you tell the difference. I was learning that difference in real time.</p><h3><strong>Part 3 — The Bug I Almost Missed</strong></h3><p>Once the filter DSL was working, I thought I was done with filters. I wasn’t.</p><p>I wrote a test where a user puts two $or blocks at the top level:</p><pre>.filters {<br>    $0.or {<br>        $0.equals(&quot;category&quot;, &quot;shoes&quot;)<br>    }<br>    $0.or {<br>        $0.equals(&quot;brand&quot;, &quot;nike&quot;)<br>    }<br>}</pre><p>And the output was:</p><pre>filters[$or][0][category][$eq]=shoes<br>filters[$or][0][brand][$eq]=nike ← collision!</pre><p>Both $or blocks were encoding starting at index [0]. Without the test, this would have silently produced wrong API results in production. I probably would have spent hours debugging a weird Strapi response before finding it.</p><p>The fix was auto-wrapping multiple top-level nodes in $and which is what Strapi expects anyway. But the real lesson was: <em>write the edge case tests</em>. Not just the happy path. Not just the basic examples from the README. The weird combinations that a real user will eventually try.</p><p>I wouldn’t have found this bug without tests. That’s what saved it.</p><h3><strong>Part 4 — Recursive Encoding (The Thing That Scared Me Most)</strong></h3><p>Populate was the hardest part of this project. Strapi’s populate system supports deep nesting you can populate a relation, then populate relations <strong>within</strong> that relation, and so on indefinitely. The encoded format looks like:</p><pre>populate[expenses][populate][splitShares][populate][ownedBy][fields][0]=id</pre><p>When I first looked at this I genuinely didn’t know where to start. I’d never written a recursive encoder before. I understood “recursive” as a textbook concept a function that calls itself but I had never actually implemented one for a real problem.</p><p>After a lot of reading and discussion I started to understand the pattern a function that calls itself with a modified prefix, going deeper into the tree until it hits a leaf node. The populate tree itself was modeled as an indirect enum:</p><pre>public indirect enum PopulateNode: Sendable {<br>    case all<br>    case field(String)<br>    case sort(String, StrapiSortOrder)<br>    case filters([FilterNode])<br>    case relation(String, [PopulateNode])<br>}</pre><p>The indirect keyword was new to me too. It’s needed because enums with associated values that reference themselves need to tell Swift the size at compile time.</p><p>The encoder recurses through the tree, building the prefix as it goes deeper:</p><pre>case .relation(let name, let children):<br>    let base = &quot;\(prefix)[\(name)]&quot;<br>    for child in children {<br>        switch child {<br>        case .relation:<br>            encode(child, prefix: &quot;\(base)[populate]&quot;, into: &amp;items)<br>        default:<br>            encode(child, prefix: base, into: &amp;items)<br>        }<br>    }</pre><p>When it finally clicked when I understood <strong>why</strong> nested relations add [populate] to the prefix but fields and filters don’t it was one of those genuine moments of satisfaction that make programming worth it. I had learned something real. Not just copy-pasted something that worked, but actually understood it.</p><p>That feeling is what keeps me going.</p><h3><strong>Part 5 — Designing the Request Layer</strong></h3><p>My initial design used a repository pattern common in many Swift networking libraries:</p><pre>let repository = StrapiRepository&lt;ArticleDTO&gt;(<br>    client: client,<br>    endpoint: StrapiEndpoint(&quot;/articles&quot;)<br>)</pre><p>I thought this was the right approach because I’d seen it in other packages. But after using it I realised it was too rigid — the endpoint is fixed at init, custom endpoints are awkward, and testing requires a mock repository instead of just a mock transport layer.</p><p>So I designed something simpler StrapiRequest:</p><pre>StrapiRequest&lt;[ArticleDTO]&gt;(<br>    endpoint: &quot;/articles&quot;,<br>    query: query<br>)</pre><p>Single vs list is handled by Swift generics naturally. StrapiRequest&lt;ArticleDTO&gt; for one item, StrapiRequest&lt;[ArticleDTO]&gt; for a list. The client’s execute method is the single entry point for everything.</p><p>One detail I almost got wrong, Strapi expects the body wrapped in { “data”: … }. I was sending it directly. A user would have gotten mysterious 400 errors with no obvious reason. I caught this during a review of the implementation and added a typed convenience init that wraps automatically:</p><pre>extension StrapiRequest {<br>    public init&lt;Body: Encodable &amp; Sendable&gt;(<br>        endpoint: String,<br>        method: HTTPMethod = .GET,<br>        body: Body,<br>        ...<br>    ) throws {<br>        struct Wrapper&lt;T: Encodable&gt;: Encodable { let data: T }<br>        self.body = try JSONEncoder().encode(Wrapper(data: body))<br>    }<br>}</pre><h3>Part 6 — Testing, Auth, and Logging</h3><h4><strong>Testing Without a Server</strong></h4><p>From the beginning I wanted the package to be fully testable without a real Strapi server. The solution was a transport abstraction a protocol that URLSession conforms to in production but a mock closure conforms to in tests:</p><pre>public protocol HTTPTransportProtocol: Sendable {<br>    func send(_ request: URLRequest) async throws -&gt; (Data, URLResponse)<br>}</pre><p>Tests intercept requests and return stubbed data without touching a network:</p><pre>let client = TestUtils.makeClient { request in<br>    #expect(request.url?.path == &quot;/api/articles&quot;)<br>    return (TestUtils.okListJSON(), TestUtils.okResponse(for: request))<br>}</pre><p>Deterministic. Parallel-safe. No flakiness. I hadn’t used this pattern before now I can’t imagine building a networking layer without it.</p><h4><strong>Logging With Correlation IDs</strong></h4><p>The built-in logger uses Apple’s OSLog and attaches a UUID to every request. You can search for that ID in Console.app and see the full lifecycle request sent, response received, or error thrown — all in one place. Sensitive headers like Authorization are automatically redacted.</p><p>Correlation IDs are such a simple idea, but they make a real difference when you’re chasing a bug through logs at midnight.</p><h3>What I Actually Built — And What It Took</h3><p>Looking back at this project, I built:</p><ul><li>A recursive filter encoder supporting arbitrary $and/$or nesting</li><li>A recursive populate encoder supporting deep nested relations</li><li>A type-safe DSL using inout + mutating that’s consistent throughout</li><li>A request layer with automatic body wrapping and response unwrapping</li><li>A protocol-based transport abstraction for parallel-safe testing</li><li>An OSLog-based logger with correlation IDs and header redaction</li><li>A protocol-based auth system supporting dynamic token sources</li><li>A comprehensive test suite covering edge cases, error paths, and real-world scenarios</li></ul><p>I did not build this alone. AI was a constant collaborator throughout. But here’s what I want to say clearly — <strong>it didn’t build it for me</strong>. It explained concepts I didn’t know. It suggested patterns I hadn’t seen. It helped me catch bugs I would have missed. But I had to understand every piece of it. I had to make every design decision. I had to write every test. When something didn’t make sense I kept pushing until it did.</p><p>That’s how I learned @resultBuilder. That’s how I learned recursive encoding. That’s how I learned the difference between inout and chaining, between value semantics and reference semantics in concurrent Swift code.</p><p>Using AI to learn is not cheating. It’s the most efficient mentorship I’ve ever had access to available at 2am when I’m stuck, infinitely patient, and never condescending.</p><h3>Try It Out</h3><p>StrapiSwiftKit is open source and available on GitHub:</p><p><a href="https://github.com/ritesh-15/strapi-swift-kit">GitHub - ritesh-15/strapi-swift-kit: A developer-friendly Swift Package that simplifies Strapi REST API integration on iOS with a type-safe query builder and clean networking layer.</a></p><pre>swift<br>.package(url: &quot;https://github.com/ritesh-15/strapi-swift-kit&quot;, from: &quot;0.2.0&quot;)</pre><p>If you’re building a Swift app on Strapi v5, give it a try. If you find a bug, open an issue. If you want to contribute, I’d genuinely love that this package is one person’s work and there’s a lot of room to grow it.</p><p>And if you’re a junior developer reading this feeling overwhelmed by all the things you don’t know yet, keep going. Ask for help. Use every tool available to you. Build things that scare you a little.</p><p>That’s the only way I know how to learn.</p><blockquote>Built by Ritesh Khore. Still learning. Always will be. That’s the point.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69d28db277f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>