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
builder
An http request builder
decoder
Closure 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
f
Closure used to modify the reponse type.
-
Modify the underlying request builder ad-hoc
Declaration
Swift
public func modifyRequest(_ f: (RequestBuilder) -> RequestBuilder)
Parameters
f
A 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
method
The HTTP method (GET, POST, PUT, PATCH)
path
A path relative to the APIClient base url that will be executing this request.
decoder
A custom JSONDecoder (usefull for handling different date formats)
builder
A closure mutating and returning a new RequestBuilder