Requestable
public protocol Requestable: Authenticable, Configurable, ResponseSerializable, Retryable, SessionManagable, Validatable, Queueable
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.
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()
}
}
-
The response type.
Declaration
Swift
associatedtype Model
-
baseURL
Default implementationThe base URL.
Default Implementation
configuration.BaseURL
Declaration
Swift
var baseURL: String
-
The path relative to base URL.
Declaration
Swift
var path: String
-
method
Default implementationThe HTTP Method.
Default Implementation
configuration.method
Declaration
Swift
var method: Alamofire.HTTPMethod
-
encoding
Default implementationThe request parameter encoding.
Default Implementation
configuration.encoding
Declaration
Swift
var encoding: Alamofire.ParameterEncoding
-
headers
Default implementationThe HTTP headers.
Default Implementation
nil
Declaration
Swift
var headers: [String : String]?
-
parameters
Default implementationThe request parameters.
Default Implementation
nil
Declaration
Swift
var parameters: Any?
-
sessionManager
Default implementationThe Alamofire Session Manager.
Default Implementation
configuration.sessionManager
Declaration
Swift
var sessionManager: Alamofire.SessionManager
-
queue
Default implementationThe queue on which reponse will be delivered.
Default Implementation
configuration.queue
Declaration
Swift
var queue: DispatchQueue?
-
credential
Default implementationThe credential.
Default Implementation
authentication.credential
Declaration
Swift
var credential: URLCredential?
-
validationBlock
Default implementationThe Alamofire validation.
Default Implementation
validation.validation
Declaration
Swift
var validationBlock: Alamofire.DataRequest.Validation?
-
acceptableStatusCodes
Default implementationThe acceptable status codes.
Default Implementation
validation.acceptableStatusCodes
Declaration
Swift
var acceptableStatusCodes: [Int]?
-
acceptableContentTypes
Default implementationThe acceptable content types.
Default Implementation
validation.acceptableContentTypes
Declaration
Swift
var acceptableContentTypes: [String]?
-
retryErrorCodes
Default implementationThe retry error codes.
Default Implementation
retry.retryErrorCodes
Declaration
Swift
var retryErrorCodes: Set<URLError.Code>
-
retryInterval
Default implementationThe retry interval.
Default Implementation
retry.retryInterval
Declaration
Swift
var retryInterval: TimeInterval
-
maxRetryAttempts
Default implementationThe max retry attempts.
Default Implementation
retry.maxRetryAttempts
Declaration
Swift
var maxRetryAttempts: Int
-
didStartRequest()
Default implementationCalled when the Request starts.
Default Implementation
Does nothing.
Declaration
Swift
func didStartRequest()
-
didCompleteRequestWithDataResponse(_:)
Default implementationCalled when the Request succeeds.
Default Implementation
Does nothing.
Declaration
Swift
func didCompleteRequestWithDataResponse(_ dataResponse: Alamofire.DataResponse<Self.Model>)
Parameters
response
The Alamofire Response
-
executeTask(_:)
Extension methodCreates a
DataRequestOperation
for the specifiedRequestable
object and asynchronously executes it.Declaration
Swift
public func executeTask(_ completionHandler: ((Alamofire.DataResponse<Self.Model>) -> Void)? = nil) -> DataRequestOperation<Self>
Parameters
completionHandler
A closure to be executed once the request has finished.
nil
by default.Return Value
The created
DataRequestOperation
. -
requestOperation(_:)
Extension methodCreates a
DataRequestOperation
for the specifiedRequestable
object.Declaration
Swift
public func requestOperation(_ completionHandler: ((Alamofire.DataResponse<Self.Model>) -> Void)? = nil) -> DataRequestOperation<Self>
Parameters
completionHandler
A closure to be executed once the operation is started and the request has finished.
nil
by default.Return Value
The created
DataRequestOperation
. -
executeTaskEventually(_:)
Extension methodCreates a
DataRequestEventuallyOperation
for the specifiedRequestable
object and asynchronously executes it when internet is reachable.Declaration
Swift
public func executeTaskEventually(_ completionHandler: ((Alamofire.DataResponse<Self.Model>) -> Void)? = nil) -> DataRequestEventuallyOperation<Self>
Parameters
completionHandler
A closure to be executed once the request has finished.
nil
by default.Return Value
The created
DataRequestEventuallyOperation
. -
requestEventuallyOperation(_:)
Extension methodCreates a
DataRequestEventuallyOperation
for the specified requestable object.Declaration
Swift
public func requestEventuallyOperation(_ completionHandler: ((Alamofire.DataResponse<Self.Model>) -> Void)? = nil) -> DataRequestEventuallyOperation<Self>
Parameters
completionHandler
A closure to be executed once the operation is started and the request has finished.
nil
by default.Return Value
The created
DataRequestEventuallyOperation
.