Mock the interaction with a web service in a Spezi-based application.
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
).
The landing page of the RequestList | The RequestList provides an overview of all sent requests. | The detail view of a single request. |
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.
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.
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.
Contributions to this project are welcome. Please make sure to read the contribution guidelines and the contributor covenant code of conduct first.
This project is licensed under the MIT License. See Licenses for more information.