RxRestClient
open class RxRestClient
ReactiveX REST Client
-
Initialize RxRestClient
Declaration
Swift
public init(baseUrl: URL? = nil, options: RxRestClientOptions = RxRestClientOptions.default)
Parameters
baseUrl
Base Url which will be used for all requests, default value is nil so you can use Absolute URL in requests
options
RxRestClientOptions object
-
Do POST Request
Declaration
Swift
public func post<T>(_ endpoint: String, object: [String : Any]) -> Observable<T> where T : ResponseState
Parameters
endpoint
Relative path of endpoint which will be appended to baseUrl
object
dictionary representing body of request
Return Value
An observable of response state
-
Do POST Request
Declaration
Swift
public func post<T>(url: URL, object: [String : Any]) -> Observable<T> where T : ResponseState
Parameters
url
Absolute url
object
dictionary representing body of request
Return Value
An observable of response state
-
Do POST Request
Declaration
Swift
public func post<T>(_ endpoint: String, array: [String]) -> Observable<T> where T : ResponseState
Parameters
endpoint
Relative path of endpoint which will be appended to baseUrl
array
array representing body of request
Return Value
An observable of response state
-
Do POST Request
Declaration
Swift
public func post<T>(url: URL, array: [String]) -> Observable<T> where T : ResponseState
Parameters
url
Absolute url
array
array representing body of request
Return Value
An observable of response state
-
Do POST Request
Declaration
Swift
public func post<T>(_ endpoint: String, body: Encodable) -> Observable<T> where T : ResponseState
Parameters
endpoint
Relative path of endpoint which will be appended to baseUrl
body
Encodable model representing body of request
Return Value
An observable of response state
-
Do PUT Request
Declaration
Swift
public func put<T>(_ endpoint: String, object: [String : Any]) -> Observable<T> where T : ResponseState
Parameters
endpoint
Relative path of endpoint which will be appended to baseUrl
object
dictionary representing body of request
Return Value
An observable of response state
-
Do PUT Request
Declaration
Swift
public func put<T>(url: URL, object: [String : Any]) -> Observable<T> where T : ResponseState
Parameters
url
Absolute url
object
dictionary representing body of request
Return Value
An observable of response state
-
Do PUT Request
Declaration
Swift
public func put<T>(_ endpoint: String, array: [String]) -> Observable<T> where T : ResponseState
Parameters
endpoint
Relative path of endpoint which will be appended to baseUrl
array
array representing body of request
Return Value
An observable of response state
-
Do PUT Request
Declaration
Swift
public func put<T>(url: URL, array: [String]) -> Observable<T> where T : ResponseState
Parameters
url
Absolute url
array
array representing body of request
Return Value
An observable of response state
-
Do PUT Request
Declaration
Swift
public func put<T>(_ endpoint: String, body: Encodable) -> Observable<T> where T : ResponseState
Parameters
endpoint
Relative path of endpoint which will be appended to baseUrl
body
Encodable model representing body of request
Return Value
An observable of response state
-
Do PATCH Request
Declaration
Swift
public func patch<T>(_ endpoint: String, object: [String : Any]) -> Observable<T> where T : ResponseState
Parameters
endpoint
Relative path of endpoint which will be appended to baseUrl
object
dictionary representing body of request
Return Value
An observable of response state
-
Do PATCH Request
Declaration
Swift
public func patch<T>(url: URL, object: [String : Any]) -> Observable<T> where T : ResponseState
Parameters
url
Absolute url
object
dictionary representing body of request
Return Value
An observable of response state
-
Do PATCH Request
Declaration
Swift
public func patch<T>(_ endpoint: String, body: Encodable) -> Observable<T> where T : ResponseState
Parameters
endpoint
Relative path of endpoint which will be appended to baseUrl
body
Encodable model representing body of request
Return Value
An observable of response state
-
Do DELETE Request
Declaration
Swift
public func delete<T>(_ endpoint: String, object: [String : Any] = [:]) -> Observable<T> where T : ResponseState
Parameters
endpoint
Relative path of endpoint which will be appended to baseUrl
object
dictionary representing body of request, default value is empty
Return Value
An observable of response state
-
Do DELETE Request
Declaration
Swift
public func delete<T>(url: URL, object: [String : Any] = [:]) -> Observable<T> where T : ResponseState
Parameters
url
Absolute url
object
dictionary representing body of request, default value is empty
Return Value
An observable of response state
-
Do DELETE Request
Declaration
Swift
public func delete<T>(_ endpoint: String, body: Encodable) -> Observable<T> where T : ResponseState
Parameters
endpoint
Relative path of endpoint which will be appended to baseUrl
body
Encodable model representing body of request
Return Value
An observable of response state
-
Do GET Request
Declaration
Swift
public func get<T>(_ endpoint: String, query: [String : Any] = [:]) -> Observable<T> where T : ResponseState
Parameters
endpoint
Relative path of endpoint which will be appended to baseUrl
query
dictionary representing query of request, default value is empty
Return Value
An observable of response state
-
Do GET Request
Declaration
Swift
public func get<T>(url: URL, query: [String : Any] = [:]) -> Observable<T> where T : ResponseState
Parameters
url
Absolute url
query
dictionary representing query of request, default value is empty
Return Value
An observable of response state
-
Do GET Request
Declaration
Swift
public func get<T>(_ endpoint: String, query: Encodable) -> Observable<T> where T : ResponseState
Parameters
endpoint
Relative path of endpoint which will be appended to baseUrl
query
Encodable model representing query of request
Return Value
An observable of response state
-
Do GET Request
Declaration
Swift
public func get<T>(url: URL, query: Encodable) -> Observable<T> where T : ResponseState
Parameters
url
Absolute url
query
Encodable model representing query of request
Return Value
An observable of response state
-
Do Get Request
Declaration
Swift
public func get<T: PagingState<R>, R: PagingResponseProtocol>( _ endpoint: String, query: PagingQueryProtocol, loadNextPageTrigger: Observable<Void>) -> Observable<T>
Parameters
endpoint
Relative path of endpoint which will be appended to baseUrl
query
PagingQueryProtocol model representing query of request with pagination
Return Value
An observable of response state with pagination
-
Do Get Request
Declaration
Swift
public func get<T: PagingState<R>, R: PagingResponseProtocol>( url: URL, query: PagingQueryProtocol, loadNextPageTrigger: Observable<Void>) -> Observable<T>
Parameters
endpoint
Relative path of endpoint which will be appended to baseUrl
query
PagingQueryProtocol model representing query of request with pagination
Return Value
An observable of response state with pagination
-
Build and return an observable of DataRequest
Declaration
Swift
public func request(_ method: HTTPMethod, _ url: URLConvertible, object: [String : Any], encoding: ParameterEncoding) -> Observable<DataRequest>
Parameters
method
Alamofire method object (example: .get, post, etc)
url
Absolute url
object
A dictionary containing all necessary options
encoding
The kind of encoding used to process parameters
Return Value
An observable of created DataRequest
-
Build and return an observable of DataRequest
Declaration
Swift
public func request(_ method: HTTPMethod, _ url: URLConvertible, array: [Any]) -> Observable<DataRequest>
Parameters
method
Alamofire method object (example: .get, post, etc)
url
Absolute url
array
An array containing all necessary options
Return Value
An observable of created DataRequest
-
Will run DataRequest
Declaration
Swift
public func run<T>(_ request: Observable<DataRequest>) -> Observable<T> where T : ResponseState
Parameters
request
An observable of the DataRequest
Return Value
An observable of response state
-
Upload images or files using multipart form data
Declaration
Swift
public func upload<T: ResponseState>( builder: MultipartFormDataBuilder, endpoint: String, method: HTTPMethod = .post, headers: HTTPHeaders? = nil) -> Observable<T>
Parameters
builder
Builder of MultipartFormData
endpoint
Relative path of endpoint which will be appended to baseUrl
method
The HTTP method.
.post
by default.headers
The HTTP headers.
nil
by default. When value isnil
the headers from options will be usedReturn Value
An observable of response state
-
Upload images or files using multipart form data
Declaration
Swift
public func upload<T: ResponseState>( builder: MultipartFormDataBuilder, to url: URLConvertible, method: HTTPMethod = .post, headers: HTTPHeaders? = nil) -> Observable<T>
Parameters
builder
Builder of MultipartFormData
url
Absolute URL
method
The HTTP method.
.post
by default.headers
The HTTP headers.
nil
by default. When value isnil
the headers from options will be used.Return Value
An observable of response state
-
Upload file using URL.
Declaration
Swift
public func upload<T: ResponseState>( _ file: URL, endpoint: String, method: HTTPMethod = .post, headers: HTTPHeaders? = nil) -> Observable<T>
Parameters
file
URL of file to be uploaded.
endpoint
Relative path of endpoint which will be appended to baseUrl.
method
The HTTP method.
.post
by default.headers
The HTTP headers.
nil
by default. When value isnil
the headers from options will be used.Return Value
An observable of response state.
-
Upload file using URL.
Declaration
Swift
public func upload<T: ResponseState>( _ file: URL, to url: URLConvertible, method: HTTPMethod = .post, headers: HTTPHeaders? = nil) -> Observable<T>
Parameters
file
An url of file to be uploaded.
url
Absolute url.
method
The HTTP method.
.post
by default.headers
The HTTP headers.
nil
by default. When value isnil
the headers from options will be used.Return Value
An observable of response state.
-
Upload file using URL.
Declaration
Swift
public func upload<T: ResponseState>( _ file: URL, endpoint: String, method: HTTPMethod = .post, headers: HTTPHeaders? = nil) -> Observable<(T?, RxProgress)>
Parameters
file
URL of file to be uploaded.
endpoint
Relative path of endpoint which will be appended to baseUrl.
method
The HTTP method.
.post
by default.headers
The HTTP headers.
nil
by default. When value isnil
the headers from options will be used.Return Value
An observable of
ResponseState
andRxProgress
tuple. -
Upload file using URL.
Declaration
Swift
public func upload<T: ResponseState>( _ file: URL, to url: URLConvertible, method: HTTPMethod = .post, headers: HTTPHeaders? = nil) -> Observable<(T?, RxProgress)>
Parameters
file
URL of file to be uploaded.
url
Absolute url.
method
The HTTP method.
.post
by default.headers
The HTTP headers.
nil
by default. When value isnil
the headers from options will be used.Return Value
An observable of
ResponseState
andRxProgress
tuple. -
Upload data.
Declaration
Swift
public func upload<T: ResponseState>( _ data: Data, endpoint: String, method: HTTPMethod = .post, headers: HTTPHeaders? = nil) -> Observable<T>
Parameters
data
A
Data
object to be uploaded.endpoint
Relative path of endpoint which will be appended to baseUrl.
method
The HTTP method.
.post
by default.headers
The HTTP headers.
nil
by default. When value isnil
the headers from options will be used.Return Value
An observable of
ResponseState
. -
Upload data
Declaration
Swift
public func upload<T: ResponseState>( _ data: Data, to url: URLConvertible, method: HTTPMethod = .post, headers: HTTPHeaders? = nil) -> Observable<T>
Parameters
data
A
Data
object to be uploaded.url
Absolute url.
method
The HTTP method.
.post
by default.headers
The HTTP headers.
nil
by default. When value isnil
the headers from options will be used.Return Value
An observable of
ResponseState
. -
Do validation of response
Declaration
Swift
open func validate(_ request: URLRequest?, _ response: HTTPURLResponse, _ data: Data?) -> Request.ValidationResult
Parameters
request
URL Request
response
URL Response
data
Response body
Return Value
ValidationResult
-
Handle errors happened during any request
Declaration
Swift
open func handleError(error: Error) -> Observable<RestResponseStatus>
Parameters
error
Error
instance caughtReturn Value
An observable of
RestResponseStatus