Better Programming
Published in

Better Programming

Modern Networking Layers in iOS Using Async/Await

A fresh look at the networking topic that takes advantage of Swift’s Concurrency Model

The Client

The Request

Configure a Request

  • Extensible interface: you can create a custom body container for your own data structure and set them directly. Just make it conforms to the HTTPSerializableBody protocol to allow the automatic serialization to data stream when needed.
  • Easy to use APIs set: you can create all of these containers directly from the static methods offered by the HTTPBody struct

Execute a Request

The Response

Validate/Modify a Response

  • nextValidator: just pass the handle to the next validator
  • failChain: stop the chain and return an error for that request
  • retry: retry the origin request with a strategy

Retry Strategy

Debugging

Other Features

Assembling API

  • API Calls are organized in namespaces based upon their context
  • Each Resource describes a type-safe approach to create a remote request
  • Each Resource contains all the logic which generate a valid HTTP Request

Conclusion