HTTPHandler
public class HTTPHandler : HTTPHandlerProtocol
HTTPHandler is a default implementation of HTTP REST client.
Important
This is a Public Preview API. It may be changed or removed at any time.-
Entry point for additional query items for the provided request.
Declaration
Swift
public weak var queryItemsProvider: AdditionalQueryItemProvider?
-
Performs the given
HTTPHandlerRequestProtocol
. When the request is completed, it tries to decode the response using theHTTPHandlerResponseDecoder
and calls the completion block.- Example:
let httpClient = HTTPHandler(baseURL: API_URL) let request = BatchRoutingRequest<RoutingRequest>(routeQueries: query) httpClient.make(request: request) { (result: Result<BatchRoutingResponse, Error>, _: Data?) in //raw data is unused switch result { case let .success(response): //handle response case let .failure(error): //handle error } }
Declaration
Swift
public func make<T>( request: HTTPHandlerRequestProtocol, decoder: HTTPHandlerResponseDecoder, completion: @escaping (Result<T, Error>, Data?) -> () ) where T: Decodable
Parameters
request
The http request.
decoder
The HTTPHandlerResponseDecoder implementation that will be used to transform the response
Data
to a givenT
.completion
The completion closure will be called after the response to the request has been processed. The raw data received is represented by
Data?
in the completion. - Example:
-
Cancels all current requests.
Declaration
Swift
public func cancelPendingRequests()
-
Performs a given
HTTPHandlerRequestProtocol
, When the request is completed, the handler tries to decode the response using theJSONResponseDecoder
, and calls the completion block.Declaration
Swift
public func make<T>(request: HTTPHandlerRequestProtocol, completion: @escaping (Result<T, Error>, Data?) -> ()) where T: Decodable
-
Performs a given
HTTPHandlerRequestProtocol
, When the request is completed, the handler tries to decode the response using theStringResponseDecoder
, and calls the completion block.Declaration
Swift
public func make(request: HTTPHandlerRequestProtocol, completion: @escaping (Result<String, Error>, Data?) -> ())