Contents

stanfordspezi/spezimockwebservice

This source file is part of the Stanford Spezi open source project

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]

Package Metadata

Repository: stanfordspezi/spezimockwebservice

Default branch: main

README: README.md