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 URLRequest for 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]
  • Creates BaseRequest instance, initialized with several TRON properties.

    Declaration

    Swift

    public init(path: String, tron: TRON)
  • Sets method variable to httpMethod and returns.

    Declaration

    Swift

    open func method(_ httpMethod: HTTPMethod) -> Self

    Parameters

    httpMethod

    http method to set on Request.

    Return Value

    configured request.

  • Sets method variable to .post and returns.

    Declaration

    Swift

    open func post() -> Self

    Return Value

    configured request.

  • Sets method variable to .connect and returns.

    Declaration

    Swift

    open func connect() -> Self

    Return Value

    configured request.

  • Sets method variable to .delete and returns.

    Declaration

    Swift

    open func delete() -> Self

    Return Value

    configured request.

  • Sets method variable to .get and returns.

    Declaration

    Swift

    open func get() -> Self

    Return Value

    configured request.

  • Sets method variable to .head and returns.

    Declaration

    Swift

    open func head() -> Self

    Return Value

    configured request.

  • Sets method variable to .options and returns.

    Declaration

    Swift

    open func options() -> Self

    Return Value

    configured request.

  • Sets method variable to .patch and returns.

    Declaration

    Swift

    open func patch() -> Self

    Return Value

    configured request.

  • Sets method variable to .put and returns.

    Declaration

    Swift

    open func put() -> Self

    Return Value

    configured request.

  • Sets method variable to .trace and returns.

    Declaration

    Swift

    open func trace() -> Self

    Return Value

    configured request.

  • Sets parameterEncoding variable to encoding and returns configured request.

    Declaration

    Swift

    open func parameterEncoding(_ encoding: ParameterEncoding) -> Self

    Parameters

    encoding

    Alamofire.ParameterEncoding value. Common values are: JSONEncoding.default, URLEncoding.default.

    Return Value

    configured request

  • Sets headers variable to headers and returns configured request.

    Declaration

    Swift

    open func headers(_ headers: HTTPHeaders) -> Self

    Parameters

    headers

    Alamofire.HTTPHeaders value.

    Return Value

    confiured request

  • Appends plugin to plugins variable and returns configured request.

    Declaration

    Swift

    open func usingPlugin(_ plugin: Plugin) -> Self

    Parameters

    plugin

    Plugin implementation

    Return Value

    configured request

  • Replaces urlBuilder with URLBuilder with the same baseURL string and behavior.

    Declaration

    Swift

    open func buildURL(_ behavior: URLBuilder.Behavior) -> Self

    Parameters

    behavior

    URL 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) -> Self

    Parameters

    interceptor

    request 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) -> Self

    Parameters

    closure

    request modifier closure

    Return Value

    configured request

  • Configures current given request by executing closure and returning.

    Declaration

    Swift

    open func configure(_ closure: (BaseRequest) -> Void) -> Self

    Parameters

    closure

    configuration closure to run

    Return Value

    configured request

  • Sets parameters into parameters variable on request. If rootKey is non-nil, parameters are wrapped in external dictionary and set into parameters using rootKey as a single key.

    Declaration

    Swift

    open func parameters(_ parameters: [String : Any], rootKey: String? = nil) -> Self

    Parameters

    parameters

    parameters to set for request

    rootKey

    Key to use in a wrapper dictionary to wrap passed parameters. Defaults to nil.

    Return Value

    configured request

  • Sets parameters into parameters variable on request. If rootKey is non-nil, parameters are wrapped in external dictionary and set into parameters using rootKey as a single key. If setNilToNull is set to true, every nil value will be converted to NSNull instance.

    Declaration

    Swift

    open func optionalParameters(_ parameters: [String : Any?], setNilToNull: Bool = false, rootKey: String? = nil) -> Self

    Parameters

    parameters

    parameters to set for request

    setNilToNull

    If true, converts nil values into NSNull instance to be presented as null when converted to JSON. Defaults to false.

    rootKey

    Key to use in a wrapper dictionary to wrap passed parameters. Defaults to nil.

    Return Value

    configured request

  • Sets stub into apiStub property, delay into apiStub.stubDelay property. Also enabled is set to apiStub.isEnabled property.

    Declaration

    Swift

    open func stub(with stub: APIStub, delay: TimeInterval = 0.0, enabled: Bool = true) -> Self

    Parameters

    stub

    stub to use when stubbing the request

    delay

    Stub delay after which stub will return results. Defaults to 0.

    enabled

    Specifies, if apiStub needs to be enabled. Defaults to true.

    Return Value

    configured request