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
See moreRequestInterceptor
, simply create a class/struct that conforms to theRequestInterceptor
protocol, and implement the one required method:intercept(resource: NetworkResource)
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 forcefail
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
See moreintercept
method returns quickly.Declaration
Swift
public protocol ResponseInterceptor
-
The protocol for creating a Response Parser
See moreDeclaration
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 moreDeclaration
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 moreDeclaration
Swift
@objc public protocol WebService