@@ -15,11 +15,16 @@ public protocol Endpoint {
1515 /// URL path component without base URI.
1616 var path : String { get }
1717
18+ /// HTTP headers.
19+ /// - Note: Provided default implementation.
1820 var headers : [ String : String ] { get }
1921
22+ /// Query of the request, expressible as a dictionary literal with non-unique keys.
23+ /// - Note: Provided default implementation.
2024 var query : URLQuery { get }
2125
2226 /// HTTP method/verb describing the action.
27+ /// - Note: Provided default implementation.
2328 var method : HTTPMethod { get }
2429}
2530
@@ -29,25 +34,49 @@ public extension Endpoint {
2934 var method : HTTPMethod { . get }
3035}
3136
37+ /// `DataEndpoint` transmits data provided in the `body` property without any further encoding.
3238public protocol DataEndpoint : Endpoint {
3339 var body : Data { get }
3440}
3541
3642#if !os(Linux)
43+ /// `UploadEndpoint` will send the provided file to the API.
44+ ///
45+ /// - Note: If the standard implementation is used, `URLSession.uploadTask( ... )` will be used.
3746public protocol UploadEndpoint : Endpoint {
47+
48+ /// File which shell be sent.
3849 var file : URL { get }
3950}
4051
52+ /// Endpoint which will be sent as a multipart HTTP request.
53+ ///
54+ /// - Note: If the standard implementation is used, the body parts will be merged into a temporary file, which will
55+ /// then be transformed to an input stream and passed to the request as a httpBodyStream.
4156public protocol MultipartEndpoint : Endpoint {
57+
58+ /// List of individual body parts.
4259 var parts : [ MultipartBodyPart ] { get }
4360}
4461#endif
4562
63+ /// The body of the endpoint with the URL query format.
4664public protocol URLEncodedEndpoint : Endpoint {
4765 var body : URLQuery { get }
4866}
4967
50- /// Endpoint protocol extending `Endpoint` having decodable associated type, which is used
68+ /// An abstract representation of endpoint, body of which is represented by Swift encodable type. It serves as an
69+ /// abstraction between the `Server` protocol and more specific `Endpoint` conforming protocols.
70+ /// Do not use this protocol to represent an encodable endpoint, use `RequestEndpoint` instead.
71+ public protocol EncodableEndpoint : Endpoint {
72+
73+ /// Returns `data` which will be sent as the body of the endpoint. Note that only the encoder is passed to
74+ /// the function. The origin of the encodable data is not specified by this protocol.
75+ /// - Parameter encoding: Server provided encoder, which will also configure headers.
76+ func body( encoding: Encoding ) throws -> Data
77+ }
78+
79+ /// Protocol extending `Endpoint` with decodable associated type, which is used
5180/// for automatic deserialization.
5281public protocol ResponseEndpoint : Endpoint {
5382 /// Associated type describing the return type conforming to `Decodable`
@@ -56,30 +85,26 @@ public protocol ResponseEndpoint: Endpoint {
5685 associatedtype Response : Decodable
5786}
5887
59- /// Endpoint protocol extending `Endpoint` encapsulating and improving sending JSON models to API.
88+ /// Protocol extending `Endpoint`, which supports sending `Encodable` data to the server.
89+ ///
90+ /// - Note: Provides default implementation for `func body(encoding: Encoding) throws -> Data`
91+ /// and `var method: HTTPMethod`.
6092public protocol RequestEndpoint : EncodableEndpoint {
61- /// Associated type describing the encodable request model for
62- /// JSON serialization. The associated type is derived from
63- /// the body property.
93+ /// Associated type describing the encodable request model for serialization. The associated type is derived
94+ /// from the body property.
6495 associatedtype Request : Encodable
65- /// Generic encodable model, which will be sent as JSON body.
96+ /// Generic encodable model, which will be sent in the body of the request .
6697 var request : Request { get }
6798}
6899
69100public extension RequestEndpoint {
101+ var method : HTTPMethod { . post }
102+
70103 func body( encoding: Encoding ) throws -> Data {
71104 try encoding. encode ( request)
72105 }
73106}
74107
75- public protocol EncodableEndpoint : Endpoint {
76- func body( encoding: Encoding ) throws -> Data
77- }
78-
79- public extension RequestEndpoint {
80- var method : HTTPMethod { . post }
81- }
82-
83- /// Typealias combining request and response API endpoint. For describing JSON
84- /// request which both sends and expects JSON model from the server.
108+ /// Typealias combining request and response API endpoint. For describing codable
109+ /// request which both sends and expects serialized model from the server.
85110public typealias RequestResponseEndpoint = RequestEndpoint & ResponseEndpoint
0 commit comments