RxRestClient
open class RxRestClient
ReactiveX REST Client
-
Initialize RxRestClient
Declaration
Swift
public init(baseUrl: URL? = nil, options: RxRestClientOptions = RxRestClientOptions.default)Parameters
baseUrlBase Url which will be used for all requests, default value is nil so you can use Absolute URL in requests
optionsRxRestClientOptions object
-
Do POST Request
Declaration
Swift
public func post<T>(_ endpoint: String, object: [String : Any]) -> Observable<T> where T : ResponseStateParameters
endpointRelative path of endpoint which will be appended to baseUrl
objectdictionary 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 : ResponseStateParameters
urlAbsolute url
objectdictionary 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 : ResponseStateParameters
endpointRelative path of endpoint which will be appended to baseUrl
arrayarray 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 : ResponseStateParameters
urlAbsolute url
arrayarray 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 : ResponseStateParameters
endpointRelative path of endpoint which will be appended to baseUrl
bodyEncodable 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 : ResponseStateParameters
endpointRelative path of endpoint which will be appended to baseUrl
objectdictionary 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 : ResponseStateParameters
urlAbsolute url
objectdictionary 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 : ResponseStateParameters
endpointRelative path of endpoint which will be appended to baseUrl
arrayarray 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 : ResponseStateParameters
urlAbsolute url
arrayarray 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 : ResponseStateParameters
endpointRelative path of endpoint which will be appended to baseUrl
bodyEncodable 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 : ResponseStateParameters
endpointRelative path of endpoint which will be appended to baseUrl
objectdictionary 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 : ResponseStateParameters
urlAbsolute url
objectdictionary 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 : ResponseStateParameters
endpointRelative path of endpoint which will be appended to baseUrl
bodyEncodable 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 : ResponseStateParameters
endpointRelative path of endpoint which will be appended to baseUrl
objectdictionary 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 : ResponseStateParameters
urlAbsolute url
objectdictionary 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 : ResponseStateParameters
endpointRelative path of endpoint which will be appended to baseUrl
bodyEncodable 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 : ResponseStateParameters
endpointRelative path of endpoint which will be appended to baseUrl
querydictionary 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 : ResponseStateParameters
urlAbsolute url
querydictionary 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 : ResponseStateParameters
endpointRelative path of endpoint which will be appended to baseUrl
queryEncodable 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 : ResponseStateParameters
urlAbsolute url
queryEncodable 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
endpointRelative path of endpoint which will be appended to baseUrl
queryPagingQueryProtocol 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
endpointRelative path of endpoint which will be appended to baseUrl
queryPagingQueryProtocol 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
methodAlamofire method object (example: .get, post, etc)
urlAbsolute url
objectA dictionary containing all necessary options
encodingThe 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
methodAlamofire method object (example: .get, post, etc)
urlAbsolute url
arrayAn 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 : ResponseStateParameters
requestAn 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
builderBuilder of MultipartFormData
endpointRelative path of endpoint which will be appended to baseUrl
methodThe HTTP method.
.postby default.headersThe HTTP headers.
nilby default. When value isnilthe 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
builderBuilder of MultipartFormData
urlAbsolute URL
methodThe HTTP method.
.postby default.headersThe HTTP headers.
nilby default. When value isnilthe 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
fileURL of file to be uploaded.
endpointRelative path of endpoint which will be appended to baseUrl.
methodThe HTTP method.
.postby default.headersThe HTTP headers.
nilby default. When value isnilthe 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
fileAn url of file to be uploaded.
urlAbsolute url.
methodThe HTTP method.
.postby default.headersThe HTTP headers.
nilby default. When value isnilthe 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
fileURL of file to be uploaded.
endpointRelative path of endpoint which will be appended to baseUrl.
methodThe HTTP method.
.postby default.headersThe HTTP headers.
nilby default. When value isnilthe headers from options will be used.Return Value
An observable of
ResponseStateandRxProgresstuple. -
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
fileURL of file to be uploaded.
urlAbsolute url.
methodThe HTTP method.
.postby default.headersThe HTTP headers.
nilby default. When value isnilthe headers from options will be used.Return Value
An observable of
ResponseStateandRxProgresstuple. -
Upload data.
Declaration
Swift
public func upload<T: ResponseState>( _ data: Data, endpoint: String, method: HTTPMethod = .post, headers: HTTPHeaders? = nil) -> Observable<T>Parameters
dataA
Dataobject to be uploaded.endpointRelative path of endpoint which will be appended to baseUrl.
methodThe HTTP method.
.postby default.headersThe HTTP headers.
nilby default. When value isnilthe 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
dataA
Dataobject to be uploaded.urlAbsolute url.
methodThe HTTP method.
.postby default.headersThe HTTP headers.
nilby default. When value isnilthe 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.ValidationResultParameters
requestURL Request
responseURL Response
dataResponse body
Return Value
ValidationResult
-
Handle errors happened during any request
Declaration
Swift
open func handleError(error: Error) -> Observable<RestResponseStatus>Parameters
errorErrorinstance caughtReturn Value
An observable of
RestResponseStatus
View on GitHub
RxRestClient Class Reference