一个轻量级且直观的 SwiftUI 组件,可帮助您调试 HTTP 请求和响应
HTTPToast
HTTPToast 是一个轻量级且直观的 SwiftUI 组件,可帮助您调试 HTTP 请求和响应。使用 HTTPToast,您可以快速轻松地跟踪网络请求的性能并识别任何潜在问题。
特征
- 显示一个弹出式 Toast,其中包含有关请求和响应的详细信息,包括 HTTP 方法、状态代码和标头。
- 可自定义的外观和行为,因此您可以使HTTPToast满足您的需求。
- 易于集成到您现有的项目中,并可用作自定义视图修改器。
开始
安装
HTTPToast 可通过 Swift Package Manager 获得。要安装它,只需将以下行添加到 Package.swift 文件中:
dependencies: [
.package(url: "https://github.com/diti223/HTTPToast.git", from: "0.1.0")
]
And then run swift package update.
Usage
To use HTTPToast, simply wrap your HTTPClient in a ToastHTTPClient and add the .modifier(httpClient) to your view. Here’s an example:
struct ContentView: View {
@State private var httpClient = ToastHTTPClient(wrapped: DummyHTTPClient())
var body: some View {
VStack {
// Your main content here
Button(action: {
self.httpClient.request(“https://www.example.com”, method: .get, headers: nil, body: nil) { result in
// Do something with the result
}
}) {
Text(“Make Request”)
}
}
.modifier(httpClient)
}
}
Contribution
HTTPToast is an open-source project, and contributions are more than welcome. If you find a bug or have an idea for a new feature, feel free to open an issue or submit a pull request.
License
HTTPToast is released under the MIT License .