BaseRequest
open class BaseRequest<Model, ErrorModel>
Base class, that contains common functionality, extracted from APIRequest and MultipartAPIRequest.
-
Serializes Data into Model
Declaration
Swift
public typealias ResponseParser = (_ request: URLRequest?, _ response: HTTPURLResponse?, _ data: Data?, _ error: Error?) throws -> Model -
Serializes received failed response into APIError
object Declaration
Swift
public typealias ErrorParser = (_ request: URLRequest?, _ response: HTTPURLResponse?, _ data: Data?, _ error: Error?) -> ErrorModel -
Relative path of current request
Declaration
Swift
public let path: String -
HTTP method
Declaration
Swift
open var method: Alamofire.HTTPMethod -
Parameters of current request.
Declaration
Swift
open var parameters: [String : Any] -
Defines how parameters are encoded.
Declaration
Swift
open var parameterEncoding: Alamofire.ParameterEncoding -
Headers, that should be used for current request. Defaults to HTTPHeaders.default
Declaration
Swift
open var headers: HTTPHeaders -
URL builder for current request
Declaration
Swift
open var urlBuilder: URLBuilder -
API stub to be used when stubbing this request
Declaration
Swift
open var apiStub: APIStub? { get set } -
Request interceptor that allows to adapt and retry requests.
Declaration
Swift
open var interceptor: RequestInterceptor? -
Closure which provides a
URLRequestfor mutation.Declaration
Swift
open var requestModifier: Session.RequestModifier? -
Queue, used to deliver result completion blocks. Defaults to TRON.resultDeliveryQueue queue.
Declaration
Swift
open var resultDeliveryQueue: DispatchQueue -
Array of plugins for current
APIRequest.Declaration
Swift
open var plugins: [Plugin] -
Sets
methodvariable tohttpMethodand returns.Declaration
Swift
open func method(_ httpMethod: HTTPMethod) -> SelfParameters
httpMethodhttp method to set on Request.
Return Value
configured request.
-
Sets
methodvariable to.postand returns.Declaration
Swift
open func post() -> SelfReturn Value
configured request.
-
Sets
methodvariable to.connectand returns.Declaration
Swift
open func connect() -> SelfReturn Value
configured request.
-
Sets
methodvariable to.deleteand returns.Declaration
Swift
open func delete() -> SelfReturn Value
configured request.
-
Sets
methodvariable to.getand returns.Declaration
Swift
open func get() -> SelfReturn Value
configured request.
-
Sets
methodvariable to.headand returns.Declaration
Swift
open func head() -> SelfReturn Value
configured request.
-
Sets
methodvariable to.optionsand returns.Declaration
Swift
open func options() -> SelfReturn Value
configured request.
-
Sets
methodvariable to.patchand returns.Declaration
Swift
open func patch() -> SelfReturn Value
configured request.
-
Sets
methodvariable to.putand returns.Declaration
Swift
open func put() -> SelfReturn Value
configured request.
-
Sets
methodvariable to.traceand returns.Declaration
Swift
open func trace() -> SelfReturn Value
configured request.
-
Sets
parameterEncodingvariable toencodingand returns configured request.Declaration
Swift
open func parameterEncoding(_ encoding: ParameterEncoding) -> SelfParameters
encodingAlamofire.ParameterEncoding value. Common values are: JSONEncoding.default, URLEncoding.default.
Return Value
configured request
-
Replaces
urlBuilderwithURLBuilderwith the same baseURL string andbehavior.Declaration
Swift
open func buildURL(_ behavior: URLBuilder.Behavior) -> SelfParameters
behaviorURL building behavior to use when constructing request.
Return Value
configured request.
-
Sets per-request Interceptor for current request and returns.
Declaration
Swift
open func intercept(using interceptor: RequestInterceptor) -> SelfParameters
interceptorrequest interceptor
Return Value
configured request
-
Sets per-request modifier to configure URLRequest, that will be created.
Declaration
Swift
open func modifyRequest(_ closure: @escaping Session.RequestModifier) -> SelfParameters
closurerequest modifier closure
Return Value
configured request
-
Configures current given request by executing
closureand returning.Declaration
Swift
open func configure(_ closure: (BaseRequest) -> Void) -> SelfParameters
closureconfiguration closure to run
Return Value
configured request
-
Sets
parametersintoparametersvariable on request. IfrootKeyis non-nil, parameters are wrapped in external dictionary and set intoparametersusingrootKeyas a single key.Declaration
Swift
open func parameters(_ parameters: [String : Any], rootKey: String? = nil) -> SelfParameters
parametersparameters to set for request
rootKeyKey to use in a wrapper dictionary to wrap passed parameters. Defaults to nil.
Return Value
configured request
-
Sets
parametersintoparametersvariable on request. IfrootKeyis non-nil, parameters are wrapped in external dictionary and set intoparametersusingrootKeyas a single key. IfsetNilToNullis set to true, every nil value will be converted toNSNullinstance.Declaration
Swift
open func optionalParameters(_ parameters: [String : Any?], setNilToNull: Bool = false, rootKey: String? = nil) -> SelfParameters
parametersparameters to set for request
setNilToNullIf true, converts nil values into NSNull instance to be presented as
nullwhen converted to JSON. Defaults to false.rootKeyKey to use in a wrapper dictionary to wrap passed parameters. Defaults to nil.
Return Value
configured request
-
Sets
stubintoapiStubproperty,delayintoapiStub.stubDelayproperty. Alsoenabledis set toapiStub.isEnabledproperty.Declaration
Swift
open func stub(with stub: APIStub, delay: TimeInterval = 0.0, enabled: Bool = true) -> SelfParameters
stubstub to use when stubbing the request
delayStub delay after which stub will return results. Defaults to 0.
enabledSpecifies, if
apiStubneeds to be enabled. Defaults to true.Return Value
configured request
View on GitHub
Install in Dash
BaseRequest Class Reference