AppBaseApi
open class AppBaseApi
Basic Api class.
Handles remote HTTP requests using Apple APIs.
-
Inits the class using the given the root url.
Declaration
Swift
public init(_ rootUrl: String)
Parameters
rootUrl
The server base url.
-
Performs a
HTTP GET
request to the given path. If the requests succeeds, thecompletion
block will be called after converting the result using the given transformer. If the request fails, the ‘errorHandler’ block will be called instead.Declaration
Swift
open func get<Type, TransformerType>( _ targetUrl: String, responseTransformer: TransformerType, success: @escaping ((Type) -> Void), failure: @escaping ((Error) -> Void), retryAttempts: Int) where TransformerType: Transformer, TransformerType.IType == AnyObject?, TransformerType.OType == Type
Parameters
targetUrl
The request path.
responseTransformer
the
Transformer
that will be used to transform the returned value from the request into the object thecompletion
expects.success
The block to be called if request succeeds.
failure
The block to be called if request fails.
retryAttempts
How many tries before calling
error
block. -
Performs a
HTTP GET
request to the given path. If the requests succeeds, thecompletion
block will be called after converting the result using the given transformer. If the request fails, the ‘errorHandler’ block will be called instead.Declaration
Swift
open func get<Type, TransformerType>( _ targetUrl: String, responseTransformer: TransformerType, parameters: [String: Any]?, headers: [String: String]?, success: @escaping ((Type) -> Void), failure: @escaping ((Error) -> Void), retryAttempts: Int) where TransformerType: Transformer, TransformerType.IType == AnyObject?, TransformerType.OType == Type
Parameters
targetUrl
The request path.
responseTransformer
the
Transformer
that will be used to transform the returned value from the request into the object thecompletion
expects.parameters
Parameters to be sent with the request.
headers
Http Headers to be sent with the request.
success
The block to be called if request succeeds.
failure
The block to be called if request fails.
retryAttempts
How many tries before calling
errorHandler
block. -
Performs a
HTTP GET
request to the given path. If the requests succeeds, thecompletion
block will be called after converting the result using the given transformer. If the request fails, the ‘errorHandler’ block will be called instead.Declaration
Swift
open func get<Type, TransformerType>( _ endpointUrl: String, targetUrl: String, responseTransformer: TransformerType, parameters: [String: Any]?, headers: [String: String]?, success: @escaping ((Type) -> Void), failure: @escaping ((Error) -> Void), retryAttempts: Int) where TransformerType: Transformer, TransformerType.IType == AnyObject?, TransformerType.OType == Type
Parameters
targetUrl
The request path.
responseTransformer
the
Transformer
that will be used to transform the returned value from the request into the object thecompletion
expects.parameters
Parameters to be sent with the request.
headers
Http Headers to be sent with the request.
success
The block to be called if request succeeds.
failure
The block to be called if request fails.
retryAttempts
How many tries before calling
errorHandler
block.
-
Performs a
HTTP POST
request to the given path. If the requests succeeds, thecompletion
block will be called after converting the result using the given transformer. If the request fails, the ‘errorHandler’ block will be called instead.Declaration
Swift
open func post<Type, TransformerType>( _ targetUrl: String, responseTransformer: TransformerType, success: @escaping ((Type) -> Void), failure: @escaping ((Error) -> Void), retryAttempts: Int) where TransformerType: Transformer, TransformerType.IType == AnyObject?, TransformerType.OType == Type
Parameters
targetUrl
The request path.
responseTransformer
the
Transformer
that will be used to transform the returned value from the request into the object thecompletion
expects.success
The block to be called if request succeeds.
failure
The block to be called if request fails.
retryAttempts
How many tries before calling
error
block. -
Performs a
HTTP POST
request to the given path. If the requests succeeds, thecompletion
block will be called after converting the result using the given transformer. If the request fails, the ‘errorHandler’ block will be called instead.Declaration
Swift
open func post<Type, TransformerType>( _ targetUrl: String, responseTransformer: TransformerType, parameters: [String: Any]?, headers: [String: String]?, success: @escaping ((Type) -> Void), failure: @escaping ((Error) -> Void), retryAttempts: Int) where TransformerType: Transformer, TransformerType.IType == AnyObject?, TransformerType.OType == Type
Parameters
targetUrl
The request path.
responseTransformer
the
Transformer
that will be used to transform the returned value from the request into the object thecompletion
expects.parameters
Parameters to be sent with the request.
headers
Http Headers to be sent with the request.
success
The block to be called if request succeeds.
failure
The block to be called if request fails.
retryAttempts
How many tries before calling
errorHandler
block. -
Performs a
HTTP POST
request to the given path. If the requests succeeds, thecompletion
block will be called after converting the result using the given transformer. If the request fails, the ‘errorHandler’ block will be called instead.Declaration
Swift
open func post<Type, TransformerType>( _ endpointUrl: String, targetUrl: String, responseTransformer: TransformerType, parameters: [String: Any]?, headers: [String: String]?, success: @escaping ((Type) -> Void), failure: @escaping ((Error) -> Void), retryAttempts: Int) where TransformerType: Transformer, TransformerType.IType == AnyObject?, TransformerType.OType == Type
Parameters
targetUrl
The request path.
responseTransformer
the
Transformer
that will be used to transform the returned value from the request into the object thecompletion
expects.parameters
Parameters to be sent with the request.
headers
Http Headers to be sent with the request.
success
The block to be called if request succeeds.
failure
The block to be called if request fails.
retryAttempts
How many tries before calling
errorHandler
block.
-
executeRequest(httpMethod:_:targetUrl:responseTransformer:parameters:headers:success:failure:retryAttempts:)
Performs a httpMethod kind request to the given path. If the requests succeeds, the
completion
block will be called after converting the result using the given transformer. If the request fails, the ‘errorHandler’ block will be called instead.Declaration
Swift
open func executeRequest<Type, TransformerType>( httpMethod: HttpMethod, _ endpointUrl: String, targetUrl: String, responseTransformer: TransformerType, parameters: [String: Any]?, headers: [String: String]?, success: @escaping ((Type) -> Void), failure: @escaping ((Error) -> Void), retryAttempts: Int) where TransformerType: Transformer, TransformerType.IType == AnyObject?, TransformerType.OType == Type
Parameters
httpMethod
Http method to execute.
targetUrl
The request path.
responseTransformer
the
Transformer
that will be used to transform the returned value from the request into the object thecompletion
expects.parameters
Parameters to be sent with the request.
headers
Http Headers to be sent with the request.
success
The block to be called if request succeeds.
failure
The block to be called if request fails.
retryAttempts
How many tries before calling
errorHandler
block.