What's New

4.3.4

2024-05-14T10:53:41Z

HTTPStubStrategy added
Plugins.StatusCode.shouldIgnore200th will ignore 200..<300

SmartNetwork

Light weight wrapper around URLSession.

The main features are:

  • strong typed responses

await manager.decodable.request(TestInfo.self, address: address)

  • predefined API for basic types: Void, Data, Image, Any(JSON)
  • async/await and closure strategies in one interface
  • use CustomDecodable to define your own decoding strategy or type
  • Plugin is like Android interceptors. Handle every request-response in runtime!
    • Plugins.StatusCode to handle http status codes or use StatusCode directly for easy mapping to human readable enumeration
    • Plugins.Basic or Plugins.Bearer for easy auth strategy
    • Plugins.TokenPlugin to update every request
  • StopTheLine mechanic to handle any case when you need to stop whole network and wait while you make something: update auth token, handle Captcha etc..
  • HTTPStubServer mocks your own network in runtime. Make your magic while your server are not ready!
  • macOS/iOS supports

New structure of network request organization based on that new interface:

public protocol RequestManagering {
    // MARK: -

    var pure: PureRequestManager { get }
    var decodable: DecodableRequestManager { get }
    var void: TypedRequestManager<Void> { get }

    // MARK: - strong

    var data: TypedRequestManager<Data> { get }
    var image: TypedRequestManager<Image> { get }
    var json: TypedRequestManager<Any> { get }

    // MARK: - optional

    var dataOptional: TypedRequestManager<Data?> { get }
    var imageOptional: TypedRequestManager<Image?> { get }
    var jsonOptional: TypedRequestManager<Any?> { get }

    // MARK: - custom

    func custom<T: CustomDecodable>(_ type: T.Type) -> TypedRequestManager<T.Object>
}

New usage of API with short autocompletion:

Task {
    let manager = RequestManager.create()
    let result = await manager.decodable.request(TestInfo.self, address: address)
    switch result {
    case .success(let obj):
        // do something with response
    case .failure(let error):
        // do something with error
    }
}

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

Last updated: Fri Nov 15 2024 13:28:39 GMT-1000 (Hawaii-Aleutian Standard Time)