SpeziMockWebService
Mock the interaction with a web service in a Spezi-based application.
Overview
The Spezi Mock Web Service Swift Package provides a Spezi Component (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
).
![]() ![]() |
![]() ![]() |
![]() ![]() |
---|---|---|
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 Component
The MockWebService
component 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 Component
in the Spezi documentation.
Example
The following example demonstrates the usage of the Swift Package in a SwiftUI View
,
accessing the MockWebService
using the @EnvironmentObject
property wrapper.
import SpeziMockWebService
import SwiftUI
struct ExampleView: View {
@EnvironmentObject 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.