Skip to content

Conversation

@zac
Copy link
Member

@zac zac commented Feb 2, 2026

Changes

Multi-Server Support

  • Definition now uses single generic parameter: Definition<T: Endpoint>
  • Server type inferred from T.Server associated type
  • Added associatedtype Server: ServerDefinition = GenericServer default to Endpoint protocol
  • New GenericServer Type, which is a built-in server implementation for simple use cases:
    • Supports development/staging/production environments
    • Configurable per-environment or single URL for all environments
    • Zero boilerplate option - endpoints can omit explicit server configuration

URLSession Mocking Framework

Test endpoints without network calls:

// Mock a successful response
try await withMock(MyEndpoint.self, action: .return(.init(data: "mocked"))) {
    let response = try await URLSession.shared.response(with: MyEndpoint())
    // response contains mocked data
}

// Mock an error response
try await withMock(MyEndpoint.self, action: .fail(.init(errorDescription: "Not found"))) {
    let endpoint = MyEndpoint()
    do {
        _ = try await URLSession.shared.response(with: endpoint)
    } catch {
        // Handle expected error
    }
}

// Mock with closure for dynamic responses
try await withMock(MyEndpoint.self) { continuation in
    // Load mock data from JSON, etc.
    continuation.resume(returning: .init(data: loadedData))
} test: {
    let response = try await URLSession.shared.response(with: MyEndpoint())
}

Also supports Combine publishers and closure-based URLSession tasks.

Additional Features

  • Swift Testing Migration - All tests converted from XCTest to Swift Testing
  • Sendable Conformance - Full Swift 6 concurrency safety throughout

Breaking Changes

Before:

struct MyEndpoint: Endpoint {
    typealias Server = TestServer
    static let definition: Definition<MyEndpoint, TestServer> = Definition(...)
}

After:

struct MyEndpoint: Endpoint {
    typealias Server = TestServer
    static let definition: Definition<MyEndpoint> = Definition(...)
}

Testing

All 31 tests passing ✅

@zac zac changed the title Simplify Definition API: Single Generic Parameter with GenericServer Default Multi-Server Support with Mocking Feb 2, 2026
@zac zac merged commit 764077c into main Feb 2, 2026
2 checks passed
@zac zac deleted the mocking-server-environments branch February 2, 2026 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants