Protocols

The following protocols are available globally.

  • Represents a Retry that is associated with Configurable. 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

    class HTTPBinStringGETService: Requestable, HTTPBinRetryable {

    let path: String = get let encoding: ParameterEncoding = .URLEncodedInURL var parameters: Any?

    init(parameters: Any?) { self.parameters = parameters }

    }

    See more

    Declaration

    Swift

    public protocol Retryable
  • Represents a Queueable that is associated with Configurable. configuration.queue by default.

    Create custom Queueable

    protocol HTTPBinQueueable: Queueable { }

    extension HTTPBinQueueable {

    var queue: DispatchQueue { return DispatchQueue.main }

    }

    Using the above Queueable

    class HTTPBinStringGETService: Requestable, HTTPBinQueueable {

    let path: String = get let encoding: ParameterEncoding = URLEncoding.default var parameters: Any?

    init(parameters: Any?) { self.parameters = parameters }

    }

    See more

    Declaration

    Swift

    public protocol Queueable
  • Represents a Validation that is associated with Configurable. 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

    class HTTPBinStringGETService: Requestable, HTTPBinValidatable {

    let path: String = get let encoding: ParameterEncoding = .URLEncodedInURL var parameters: Any?

    init(parameters: Any?) { self.parameters = parameters }

    }

    See more

    Declaration

    Swift

    public protocol Validatable
  • Represents a ResponseSerializable that is associated with Configurable. 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

    class HTTPBinStringGETService: Requestable, HTTPBinResponseSerializable {

    let path: String = get let encoding: ParameterEncoding = .URLEncodedInURL var parameters: Any?

    init(parameters: Any?) { self.parameters = parameters }

    }

    See more

    Declaration

    Swift

    public protocol ResponseSerializable
  • Represents an Authenticable that is associated with Configurable. 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

    class HTTPBinStringGETService: Requestable, HTTPBinAuthenticable {

    let path: String = get let encoding: ParameterEncoding = URLEncoding.default var parameters: Any?

    init(parameters: Any?) { self.parameters = parameters }

    }

    See more

    Declaration

    Swift

    public protocol Authenticable
  • Represents a Configurable that is associated with Requestable. 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

    class HTTPBinStringGETService: Requestable, HTTPBinConfigurable {

    let path: String = get let encoding: ParameterEncoding = URLEncoding.default var parameters: Any?

    init(parameters: Any?) { self.parameters = parameters }

    }

    See more

    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/se>\(n>idse>)s> self.parameters = parameters }

    }

    Consuming the request.

    import Restofire
    import Alamofire

    class ViewController: UIViewController {

    var request: PersonPOSTService! var person: Any!

    func createPerson() { request = PersonPOSTService(id: 123456789, parameters: person).executeTask() }

    deinit { request.cancel() }

    }

    See more

    Declaration

  • Represents a Alamofire.SessionManager that is associated with Configurable. 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

    class HTTPBinStringGETService: Requestable, HTTPBinSessionManagable {

    let path: String = get let encoding: ParameterEncoding = URLEncoding.default var parameters: Any?

    init(parameters: Any?) { self.parameters = parameters }

    }

    See more

    Declaration

    Swift

    public protocol SessionManagable