Endpoint
public final class Endpoint<Response> : CustomStringConvertible, CustomDebugStringConvertible
extension Endpoint: URLResponseCapable
extension Endpoint: URLRequestConvertible
Typed high level abstraction of a service request and response
This class is parametrized over the response type expectation The request configuration associated with this Endpoint is encoded in the RequestBuilder.
-
Declaration
Swift
public var debugDescription: String { get } -
The closure responsible for decoding an http response.
Declaration
Swift
public let decode: (Data) throws -> Response -
The request builder instance used to configure the HTTP request.
Declaration
Swift
public var builder: RequestBuilder -
Declaration
Swift
public var description: String { get } -
Constructs a new Endpoint
Declaration
Swift
public init(builder: RequestBuilder, decode: @escaping (Data) throws -> Response)Parameters
builderAn http request builder
decoderClosure used to decode Data into the expected response type.
-
Transform Endpoint into a new one
This is handy when you want to select a portion of the http response, e.g when the data of interest is enveloped by meta data.
Declaration
Swift
public func map<N>(_ f: @escaping ((Response) throws -> N)) -> Endpoint<N>Parameters
fClosure used to modify the reponse type.
-
Modify the underlying request builder ad-hoc
Declaration
Swift
public func modifyRequest(_ f: (RequestBuilder) -> RequestBuilder)Parameters
fA function that further configures the http request
-
Declaration
Swift
public typealias ResponseType = Response -
Declaration
Swift
public func handle(data: Data) throws -> Response -
Undocumented
Declaration
Swift
public func asURLRequest(baseURL: URL?) -> URLRequest
-
Undocumented
Declaration
Swift
public convenience init( method: RequestBuilder.Method, path: Path, _ builder: ((RequestBuilder) -> RequestBuilder)? = nil )
-
Undocumented
Declaration
Swift
public convenience init( method: RequestBuilder.Method, path: Path, _ builder: ((RequestBuilder) -> RequestBuilder)? = nil )
-
Creates and endpoint specification
Declaration
Swift
public convenience init( method: RequestBuilder.Method, path: Path, decoder: JSONDecoder? = nil, _ builder: ((RequestBuilder) -> RequestBuilder)? = nil )Parameters
methodThe HTTP method (GET, POST, PUT, PATCH)
pathA path relative to the APIClient base url that will be executing this request.
decoderA custom JSONDecoder (usefull for handling different date formats)
builderA closure mutating and returning a new RequestBuilder
Endpoint Class Reference