HTTPRequestProtocol

public protocol HTTPRequestProtocol : AnyObject

HTTP请求协议,主要用于处理方法中Self参数、错误处理等

  • 是否自动显示错误信息

    Declaration

    Swift

    var autoShowError: Bool { get set }
  • 当前网络错误

    Declaration

    Swift

    var error: Error? { get }
  • 显示网络错误,默认显示Toast提示

    Declaration

    Swift

    func showError()
  • 开始请求

    Declaration

    Swift

    func start() -> Self
  • 取消请求

    Declaration

    Swift

    func cancel()

Available where Self: HTTPRequest

  • start(success:failure:) Extension method

    开始请求并指定成功、失败句柄

    Declaration

    Swift

    @discardableResult
    public func start(success: (@MainActor @Sendable (Self) -> Void)?, failure: (@MainActor @Sendable (Self) -> Void)?) -> Self
  • start(completion:) Extension method

    开始请求并指定完成句柄

    Declaration

    Swift

    @discardableResult
    public func start(completion: (@MainActor @Sendable (Self) -> Void)?) -> Self
  • requestCancelledBlock(_:) Extension method

    请求取消句柄,不一定主线程调用

    Declaration

    Swift

    @discardableResult
    public func requestCancelledBlock(_ block: (@Sendable (Self) -> Void)?) -> Self
  • response(_:) Extension method

    自定义响应完成句柄

    Declaration

    Swift

    @discardableResult
    public func response(_ completion: (@MainActor @Sendable (Self) -> Void)?) -> Self
  • responseSuccess(_:) Extension method

    自定义响应成功句柄

    Declaration

    Swift

    @discardableResult
    public func responseSuccess(_ block: (@MainActor @Sendable (Self) -> Void)?) -> Self
  • responseFailure(_:) Extension method

    自定义响应失败句柄

    Declaration

    Swift

    @discardableResult
    public func responseFailure(_ block: (@MainActor @Sendable (Self) -> Void)?) -> Self
  • responseCache(_:) Extension method

    解析缓存响应句柄,必须在start之前调用生效

    Declaration

    Swift

    @discardableResult
    public func responseCache(_ block: (@MainActor @Sendable (Self) -> Void)?) -> Self
  • response() Extension method, asynchronous

    异步获取完成响应,注意非Task取消也会触发(Continuation流程)

    Declaration

    Swift

    public func response() async -> Self
  • responseSuccess() Extension method, asynchronous

    异步获取成功响应,注意非Task取消也会触发(Continuation流程)

    Declaration

    Swift

    public func responseSuccess() async throws -> Self
  • responseModel(of:designatedPath:) Extension method, asynchronous

    异步获取响应模型,注意非Task取消也会触发(Continuation流程)

    Declaration

    Swift

    public func responseModel<T>(of type: T.Type, designatedPath: String? = nil) async throws -> T? where T : AnyModel, T : Sendable
  • safeResponseModel(of:designatedPath:) Extension method, asynchronous

    异步获取安全响应模型,注意非Task取消也会触发(Continuation流程)

    Declaration

    Swift

    public func safeResponseModel<T>(of type: T.Type, designatedPath: String? = nil) async throws -> T where T : AnyModel, T : Sendable