@@ -17,68 +17,76 @@ public enum Body {
1717///
1818/// Highly inspired by https://swiftwithmajid.com/2021/02/10/building-type-safe-networking-in-swift/
1919public struct Request < Output> {
20- /// request relative endpoint
21- public let endpoint : Endpoint
20+ /// request relative path
21+ public let path : Path
2222 public let method : Method
2323 public let body : Body ?
2424 public let query : [ String : QueryParam ]
25- public private ( set ) var cachePolicy : URLRequest . CachePolicy = . useProtocolCachePolicy
26- public private ( set ) var headers : HTTPHeaderFields = [ : ]
25+ public var cachePolicy : URLRequest . CachePolicy = . useProtocolCachePolicy
26+ public var headers : HTTPHeaderFields = [ : ]
2727
2828 /// Creates a request suitable for a HTTP GET
29- public static func get( _ endpoint : Endpoint , query: [ String : QueryParam ] = [ : ] ) -> Self {
30- self . init ( endpoint : endpoint , method: . get, query: query, body: nil )
29+ public static func get( _ path : Path , query: [ String : QueryParam ] = [ : ] ) -> Self {
30+ self . init ( path : path , method: . get, query: query, body: nil )
3131 }
3232
3333 /// Creates a request suitable for a HTTP POST with a `Encodable` body
34- public static func post( _ endpoint : Endpoint , body: Encodable ? , query: [ String : QueryParam ] = [ : ] )
34+ public static func post( _ path : Path , body: Encodable ? , query: [ String : QueryParam ] = [ : ] )
3535 -> Self {
36- self . init ( endpoint : endpoint , method: . post, query: query, body: body. map ( Body . encodable) )
36+ self . init ( path : path , method: . post, query: query, body: body. map ( Body . encodable) )
3737 }
3838
3939 /// Creates a request suitable for a HTTP POST with a `MultipartFormData` body
4040 @_disfavoredOverload
41- public static func post( _ endpoint : Endpoint , body: MultipartFormData ? , query: [ String : QueryParam ] = [ : ] )
41+ public static func post( _ path : Path , body: MultipartFormData ? , query: [ String : QueryParam ] = [ : ] )
4242 -> Self {
43- self . init ( endpoint : endpoint , method: . post, query: query, body: body. map ( Body . multipart) )
43+ self . init ( path : path , method: . post, query: query, body: body. map ( Body . multipart) )
4444 }
4545
4646 /// Creates a request suitable for a HTTP PUT with a `Encodable` body
47- public static func put( _ endpoint : Endpoint , body: Encodable , query: [ String : QueryParam ] = [ : ] )
47+ public static func put( _ path : Path , body: Encodable , query: [ String : QueryParam ] = [ : ] )
4848 -> Self {
49- self . init ( endpoint : endpoint , method: . put, query: query, body: . encodable( body) )
49+ self . init ( path : path , method: . put, query: query, body: . encodable( body) )
5050 }
5151
5252 /// Creates a request suitable for a HTTP PUT with a `MultipartFormData` body
53- public static func put( _ endpoint : Endpoint , body: MultipartFormData , query: [ String : QueryParam ] = [ : ] )
53+ public static func put( _ path : Path , body: MultipartFormData , query: [ String : QueryParam ] = [ : ] )
5454 -> Self {
55- self . init ( endpoint: endpoint, method: . put, query: query, body: . multipart( body) )
55+ self . init ( path: path, method: . put, query: query, body: . multipart( body) )
56+ }
57+
58+ /// Create a HTTP PUT request with no body
59+ public static func put( _ path: Path , query: [ String : QueryParam ] = [ : ] ) -> Self {
60+ self . init ( path: path, method: . put, query: query, body: nil )
5661 }
5762
5863 /// Creates a request suitable for a HTTP PATCH with a `Encodable` body
59- public static func patch( _ endpoint : Endpoint , body: Encodable , query: [ String : QueryParam ] = [ : ] )
64+ public static func patch( _ path : Path , body: Encodable , query: [ String : QueryParam ] = [ : ] )
6065 -> Self {
61- self . init ( endpoint : endpoint , method: . patch, query: query, body: . encodable( body) )
66+ self . init ( path : path , method: . patch, query: query, body: . encodable( body) )
6267 }
6368
6469 /// Creates a request suitable for a HTTP PATCH with a `MultipartFormData` body
65- public static func patch( _ endpoint : Endpoint , body: MultipartFormData , query: [ String : QueryParam ] = [ : ] )
70+ public static func patch( _ path : Path , body: MultipartFormData , query: [ String : QueryParam ] = [ : ] )
6671 -> Self {
67- self . init ( endpoint : endpoint , method: . patch, query: query, body: . multipart( body) )
72+ self . init ( path : path , method: . patch, query: query, body: . multipart( body) )
6873 }
6974
7075 /// Creates a request suitable for a HTTP DELETE
71- /// Default implementation does not allow for sending a body. If you need such a case extend Request with your
72- /// own init method
73- public static func delete( _ endpoint: Endpoint , query: [ String : QueryParam ] = [ : ] ) -> Self {
74- self . init ( endpoint: endpoint, method: . delete, query: query, body: nil )
76+ public static func delete( _ path: Path , query: [ String : QueryParam ] = [ : ] ) -> Self {
77+ self . init ( path: path, method: . delete, query: query, body: nil )
78+ }
79+
80+ /// Creates a DELETE request with a Encodable body
81+ public static func delete( _ path: Path , body: Encodable , query: [ String : QueryParam ] = [ : ] ) -> Self {
82+ self . init ( path: path, method: . delete, query: query, body: nil )
7583 }
7684
7785 /// Creates a Request.
7886 ///
7987 /// Use this init only if default provided static initializers (`.get`, `.post`, `.put`, `patch`, `.delete`) do not suit your needs.
80- public init ( endpoint : Endpoint , method: Method , query: [ String : QueryParam ] , body: Body ? ) {
81- self . endpoint = endpoint
88+ public init ( path : Path , method: Method , query: [ String : QueryParam ] , body: Body ? ) {
89+ self . path = path
8290 self . method = method
8391 self . body = body
8492 self . query = query
0 commit comments