Protocols
The following protocols are available globally.
-
Represents a
Retry
that is associated withConfigurable
.configuration.retry
by default.Create custom Retryable
protocol HTTPBinRetryable: Retryable { } extension HTTPBinRetryable { var retry: Retry { var retry = Retry() retry.retryErrorCodes = [.timedOut,.networkConnectionLost] retry.retryInterval = 20 retry.maxRetryAttempts = 10 return retry } }
Using the above Retryable
See moreclass HTTPBinStringGETService: Requestable, HTTPBinRetryable { let path: String = "get" let encoding: ParameterEncoding = .URLEncodedInURL var parameters: Any? init(parameters: Any?) { self.parameters = parameters } }
Declaration
Swift
public protocol Retryable
-
Represents a
Queueable
that is associated withConfigurable
.configuration.queue
by default.Create custom Queueable
protocol HTTPBinQueueable: Queueable { } extension HTTPBinQueueable { var queue: DispatchQueue { return DispatchQueue.main } }
Using the above Queueable
See moreclass HTTPBinStringGETService: Requestable, HTTPBinQueueable { let path: String = "get" let encoding: ParameterEncoding = URLEncoding.default var parameters: Any? init(parameters: Any?) { self.parameters = parameters } }
Declaration
Swift
public protocol Queueable
-
Represents a
Validation
that is associated withConfigurable
.configuration.validation
by default.Create custom Validatable
protocol HTTPBinValidatable: Validatable { } extension HTTPBinValidatable { var validation: Validation { var validation = Validation() validation.acceptableStatusCodes = [200..<300] validation.acceptableContentTypes = ["application/json"] return validation } }
Using the above Validatable
See moreclass HTTPBinStringGETService: Requestable, HTTPBinValidatable { let path: String = "get" let encoding: ParameterEncoding = .URLEncodedInURL var parameters: Any? init(parameters: Any?) { self.parameters = parameters } }
Declaration
Swift
public protocol Validatable
-
Represents a
ResponseSerializable
that is associated withConfigurable
.configuration.responseSerializer
by default.Create custom ResponseSerializable
protocol HTTPBinResponseSerializable: ResponseSerializable { } extension HTTPBinResponseSerializable { var responseSerializer: Alamofire.DataResponseSerializer<Model> { return Alamofire.Request.customResponseSerializer() } }
Using the above ResponseSerializable
See moreclass HTTPBinStringGETService: Requestable, HTTPBinResponseSerializable { let path: String = "get" let encoding: ParameterEncoding = .URLEncodedInURL var parameters: Any? init(parameters: Any?) { self.parameters = parameters } }
Declaration
Swift
public protocol ResponseSerializable
-
Represents an
Authenticable
that is associated withConfigurable
.configuration.authentication
by default.Create custom Authenticable
protocol HTTPBinAuthenticable: Authenticable { } extension HTTPBinAuthenticable { var configuration: Configuration { var authentication = Authentication() authentication.credential = URLCredential(user: "user", password: "password", persistence: .forSession) return authentication } }
Using the above Authenticable
See moreclass HTTPBinStringGETService: Requestable, HTTPBinAuthenticable { let path: String = "get" let encoding: ParameterEncoding = URLEncoding.default var parameters: Any? init(parameters: Any?) { self.parameters = parameters } }
Declaration
Swift
public protocol Authenticable
-
Represents a
Configurable
that is associated withRequestable
.Restofire.defaultConfiguration()
by default.Create custom Configurable
protocol HTTPBinConfigurable: Configurable { } extension HTTPBinConfigurable { var configuration: Configuration { var config = Configuration() config.baseURL = "https://httpbin.org/" config.logging = Restofire.defaultConfiguration.logging return config } }
Using the above Configurable
See moreclass HTTPBinStringGETService: Requestable, HTTPBinConfigurable { let path: String = "get" let encoding: ParameterEncoding = URLEncoding.default var parameters: Any? init(parameters: Any?) { self.parameters = parameters } }
Declaration
Swift
public protocol Configurable
-
Represents an HTTP Request that can be asynchronously executed. You must provide a
path
.Creating a request.
import Restofire import Alamofire struct PersonPOSTService: Requestable { let path: String let method: Alamofire.HTTPMethod = .post let parameters: Any? init(id: String, parameters: Any? = nil) { self.path = "person/\(id)" self.parameters = parameters } }
Consuming the request.
See moreimport Restofire import Alamofire class ViewController: UIViewController { var request: PersonPOSTService! var person: Any! func createPerson() { request = PersonPOSTService(id: "123456789", parameters: person).executeTask() } deinit { request.cancel() } }
Declaration
Swift
public protocol Requestable: Authenticable, Configurable, ResponseSerializable, Retryable, SessionManagable, Validatable, Queueable
-
Represents a
Alamofire.SessionManager
that is associated withConfigurable
.configuration.sessionManager
by default.Create custom SessionManagable
protocol HTTPBinSessionManagable: SessionManagable { } extension HTTPBinSessionManagable { var sessionManager: Alamofire.SessionManager { let sessionConfiguration = URLSessionConfiguration.default sessionConfiguration.timeoutIntervalForRequest = 7 sessionConfiguration.timeoutIntervalForResource = 7 sessionConfiguration.httpAdditionalHeaders = Alamofire.SessionManager.defaultHTTPHeaders return Alamofire.SessionManager(configuration: sessionConfiguration) } }
Using the above SessionManagable
See moreclass HTTPBinStringGETService: Requestable, HTTPBinSessionManagable { let path: String = "get" let encoding: ParameterEncoding = URLEncoding.default var parameters: Any? init(parameters: Any?) { self.parameters = parameters } }
Declaration
Swift
public protocol SessionManagable