SpeziMockWebService

1.0.0

A Spezi-based Swift Package to mock the interaction with a web service in a Spezi-based app.
StanfordSpezi/SpeziMockWebService

What's New

1.0.0

2024-01-09T22:12:49Z

What's Changed

  • Upgrade to Spezi 1.0 and minor documentation upgrades by @Supereg in #15

Full Changelog: 0.3.0...1.0.0

SpeziMockWebService

Build and Test codecov DOI

Mock the interaction with a web service in a Spezi-based application.

Overview

The Spezi Mock Web Service Swift Package provides a Spezi Module (MockWebService) to mock the interaction with a web service and display the requests in a user interface that can be used for demonstrations and debugging purposes (RequestList).

Screenshot showing an empty list with a placeholder stating: 'The Mock Web Service will display all requests that would be triggered by the application.' Screenshot showing an empty list with a placeholder stating: 'The Mock Web Service will display all requests that would be triggered by the application.' Screenshot showing two requests in the mock request list: One is a deletion request, and one is an addition. Screenshot showing two requests in the mock request list: One is a deletion request, and one is an addition. Detail view of a mock request, showing that it is an addition with a short JSON body. Detail view of a mock request, showing that it is an addition with a short JSON body.
The landing page of the RequestList The RequestList provides an overview of all sent requests. The detail view of a single request.

Setup

1. Add Spezi Mock Web Service as a Dependency

You need to add the Spezi Mock Web Service Swift package to your app in Xcode or Swift package.

Important

If your application is not yet configured to use Spezi, follow the Spezi setup article setup the core Spezi infrastructure.

2. Register the Module

The MockWebService module needs to be registered in a Spezi-based application using the configuration in a SpeziAppDelegate:

class ExampleAppDelegate: SpeziAppDelegate {
    override var configuration: Configuration {
        Configuration {
            MockWebService()
            // ...
        }
    }
}

Note

You can learn more about a Module in the Spezi documentation.

Example

The following example demonstrates the usage of the Swift Package in a SwiftUI View, accessing the MockWebService using the @Environment property wrapper.

import SpeziMockWebService
import SwiftUI


struct ExampleView: View {
    @Environment(MockWebService.self) var webService: MockWebService
    
    
    var body: some View {
        NavigationStack {
            RequestList()
            // ...
        }
    }
    
    
    private func sendMockUploadRequests() async throws {
        try await webService.upload(path: "Test", body: #"{"test": "test"}"#)
        try await webService.remove(path: "TestRemoval")
    }
}

For more information, please refer to the API documentation.

Contributing

Contributions to this project are welcome. Please make sure to read the contribution guidelines and the contributor covenant code of conduct first.

License

This project is licensed under the MIT License. See Licenses for more information.

Spezi Footer Spezi Footer

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

Last updated: Mon Dec 09 2024 02:08:28 GMT-1000 (Hawaii-Aleutian Standard Time)