模拟基于 Spezi 的应用程序与 Web 服务的交互。
Spezi Mock Web Service Swift 包提供了一个 Spezi 模块 (MockWebService
),用于模拟与 Web 服务的交互,并在用户界面中显示请求,可用于演示和调试目的 (RequestList
)。
![]() ![]() |
![]() ![]() |
![]() ![]() |
---|---|---|
RequestList 的登陆页面 | RequestList 提供了所有已发送请求的概览。 | 单个请求的详细视图。 |
您需要在 Xcode 中的应用程序 或 Swift 包 中添加 Spezi Mock Web Service Swift 包。
重要提示
如果您的应用程序尚未配置为使用 Spezi,请按照 Spezi 设置文章 设置核心 Spezi 基础设施。
需要在基于 Spezi 的应用程序中使用 configuration
在 SpeziAppDelegate
中注册 MockWebService
模块
class ExampleAppDelegate: SpeziAppDelegate {
override var configuration: Configuration {
Configuration {
MockWebService()
// ...
}
}
}
注意
以下示例演示了 Swift 包在 SwiftUI View
中的用法,使用 @Environment
属性包装器访问 MockWebService
。
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")
}
}
有关更多信息,请参阅 API 文档。
欢迎对本项目做出贡献。请务必先阅读 贡献指南 和 贡献者公约行为准则。
本项目采用 MIT 许可证。有关更多信息,请参阅 许可证。