Protocols

The following protocols are available globally.

  • Request Interceptors are called just before a request is about to fire over the network. Request Interceptors are called after all the constraints of a request a satisfied, but just before a request is about to go over the network. This makes them especially useful to add parameters to the requests they need to succeed.

    Your interceptors are always called in the order they are passed into the Swifty Initializer. Also, each interceptor’s result is then sent into the next one, that is, the interceptors are executed serially.

    You should not do too much work synchronously in your request interceptors, since your requests have to wait for the interceptors before firing over the network. If you need to do long running tasks before requests, try using a Constraint instead.

    To create a RequestInterceptor, simply create a class/struct that conforms to the RequestInterceptor protocol, and implement the one required method: intercept(resource: NetworkResource)

    See more

    Declaration

    Swift

    public protocol RequestInterceptor
  • Response Interceptors are called just before a response is going to be returned back to the caller.

    Examples of things you can do here:

    • Collect/Log statistics about the failure rate of responses by counting the number of errors
    • Update your session information from every response, if they have any
    • You can even force succeed or force fail your responses in Response Interceptors

    You should not do too much work synchronously in your response interceptors, since your responses have to wait for the interceptors before reaching back the caller. If you have to do long running tasks here, try dispatching them instead of running them synchronously, so that at least the intercept method returns quickly.

    See more

    Declaration

    Swift

    public protocol ResponseInterceptor
  • The protocol for creating a Response Parser

    See more

    Declaration

    Swift

    public protocol ResponseParser
  • WebServiceNetworkInterface: A protocol which lets any object become a bridge between a webservice and the internet. Instances of Swifty conform to this protocol by default

    Conformance to this only requires the implementation of one method: loadResource(resource: completion:)

    See more

    Declaration

    Swift

    @objc
    public protocol WebServiceNetworkInterface : AnyObject
  • WebService is a protocol which helps you write your network requests in a declarative, type-safe and expressive way.

    You start by creating a class, putting in your server’s base URL & a network interface, and begin writing your network requests as functions

    See more

    Declaration

    Swift

    @objc
    public protocol WebService