@@ -24,31 +24,31 @@ public struct Request<Output> {
24
24
public let query : [ String : QueryParam ]
25
25
public var cachePolicy : URLRequest . CachePolicy = . useProtocolCachePolicy
26
26
public var headers : HTTPHeaderFields = [ : ]
27
-
27
+
28
28
/// Creates a request suitable for a HTTP GET
29
29
public static func get( _ path: Path , query: [ String : QueryParam ] = [ : ] ) -> Self {
30
30
self . init ( path: path, method: . get, query: query, body: nil )
31
31
}
32
-
32
+
33
33
/// Creates a request suitable for a HTTP POST with a `Encodable` body
34
34
public static func post( _ path: Path , body: Encodable ? , query: [ String : QueryParam ] = [ : ] )
35
35
-> Self {
36
36
self . init ( path: path, method: . post, query: query, body: body. map ( Body . encodable) )
37
37
}
38
-
38
+
39
39
/// Creates a request suitable for a HTTP POST with a `MultipartFormData` body
40
40
@_disfavoredOverload
41
41
public static func post( _ path: Path , body: MultipartFormData ? , query: [ String : QueryParam ] = [ : ] )
42
42
-> Self {
43
43
self . init ( path: path, method: . post, query: query, body: body. map ( Body . multipart) )
44
44
}
45
-
45
+
46
46
/// Creates a request suitable for a HTTP PUT with a `Encodable` body
47
47
public static func put( _ path: Path , body: Encodable , query: [ String : QueryParam ] = [ : ] )
48
48
-> Self {
49
49
self . init ( path: path, method: . put, query: query, body: . encodable( body) )
50
50
}
51
-
51
+
52
52
/// Creates a request suitable for a HTTP PUT with a `MultipartFormData` body
53
53
public static func put( _ path: Path , body: MultipartFormData , query: [ String : QueryParam ] = [ : ] )
54
54
-> Self {
@@ -59,19 +59,19 @@ public struct Request<Output> {
59
59
public static func put( _ path: Path , query: [ String : QueryParam ] = [ : ] ) -> Self {
60
60
self . init ( path: path, method: . put, query: query, body: nil )
61
61
}
62
-
62
+
63
63
/// Creates a request suitable for a HTTP PATCH with a `Encodable` body
64
64
public static func patch( _ path: Path , body: Encodable , query: [ String : QueryParam ] = [ : ] )
65
65
-> Self {
66
66
self . init ( path: path, method: . patch, query: query, body: . encodable( body) )
67
67
}
68
-
68
+
69
69
/// Creates a request suitable for a HTTP PATCH with a `MultipartFormData` body
70
70
public static func patch( _ path: Path , body: MultipartFormData , query: [ String : QueryParam ] = [ : ] )
71
71
-> Self {
72
72
self . init ( path: path, method: . patch, query: query, body: . multipart( body) )
73
73
}
74
-
74
+
75
75
/// Creates a request suitable for a HTTP DELETE
76
76
public static func delete( _ path: Path , query: [ String : QueryParam ] = [ : ] ) -> Self {
77
77
self . init ( path: path, method: . delete, query: query, body: nil )
@@ -81,7 +81,7 @@ public struct Request<Output> {
81
81
public static func delete( _ path: Path , body: Encodable , query: [ String : QueryParam ] = [ : ] ) -> Self {
82
82
self . init ( path: path, method: . delete, query: query, body: nil )
83
83
}
84
-
84
+
85
85
/// Creates a Request.
86
86
///
87
87
/// Use this init only if default provided static initializers (`.get`, `.post`, `.put`, `patch`, `.delete`) do not suit your needs.
@@ -91,22 +91,22 @@ public struct Request<Output> {
91
91
self . body = body
92
92
self . query = query
93
93
}
94
-
94
+
95
95
/// Adds headers to the request
96
96
public func headers( _ newHeaders: [ HTTPHeader : String ] ) -> Self {
97
97
var request = self
98
-
98
+
99
99
request. headers. merge ( newHeaders) { $1 }
100
-
100
+
101
101
return request
102
102
}
103
-
103
+
104
104
/// Configures request cache policy
105
105
public func cachePolicy( _ policy: URLRequest . CachePolicy ) -> Self {
106
106
var request = self
107
-
107
+
108
108
request. cachePolicy = policy
109
-
109
+
110
110
return request
111
111
}
112
112
}
0 commit comments