@@ -119,27 +119,32 @@ extension Endpoint where A == () {
119
119
/// - method: the HTTP method
120
120
/// - url: the endpoint's URL
121
121
/// - accept: the content type for the `Accept` header
122
+ /// - contentType: the content type for the `Content-Type` header
123
+ /// - body: the body of the request.
122
124
/// - headers: additional headers for the request
123
125
/// - expectedStatusCode: the status code that's expected. If this returns false for a given status code, parsing fails.
126
+ /// - timeOutInterval: the timeout interval for his request
124
127
/// - query: query parameters to append to the url
125
- public init ( _ method: Method , url: URL , accept: ContentType ? = nil , headers: [ String : String ] = [ : ] , expectedStatusCode: @escaping ( Int ) -> Bool = expected200to300, query: [ String : String ] = [ : ] ) {
126
- self . init ( method, url: url, accept: accept, headers: headers, expectedStatusCode: expectedStatusCode, query: query, parse: { _, _ in . success( ( ) ) } )
128
+ public init ( _ method: Method , url: URL , accept: ContentType ? = nil , contentType : ContentType ? = nil , body : Data ? = nil , headers: [ String : String ] = [ : ] , expectedStatusCode: @escaping ( Int ) -> Bool = expected200to300, timeOutInterval : TimeInterval = 10 , query: [ String : String ] = [ : ] ) {
129
+ self . init ( method, url: url, accept: accept, contentType : contentType , body : body , headers: headers, expectedStatusCode: expectedStatusCode, timeOutInterval : timeOutInterval , query: query, parse: { _, _ in . success( ( ) ) } )
127
130
}
128
131
129
132
/// Creates a new endpoint without a parse function.
130
133
///
131
134
/// - Parameters:
135
+ /// - method: the HTTP method
132
136
/// - json: the HTTP method
133
137
/// - url: the endpoint's URL
134
138
/// - accept: the content type for the `Accept` header
135
139
/// - body: the body of the request. This gets encoded using a default `JSONEncoder` instance.
136
140
/// - headers: additional headers for the request
137
141
/// - expectedStatusCode: the status code that's expected. If this returns false for a given status code, parsing fails.
142
+ /// - timeOutInterval: the timeout interval for his request
138
143
/// - query: query parameters to append to the url
139
144
/// - encoder: the encoder that's used for encoding `A`s.
140
- public init < B: Encodable > ( json method: Method , url: URL , accept: ContentType ? = . json, body: B , headers: [ String : String ] = [ : ] , expectedStatusCode: @escaping ( Int ) -> Bool = expected200to300, query: [ String : String ] = [ : ] , encoder: JSONEncoder = JSONEncoder ( ) ) {
145
+ public init < B: Encodable > ( json method: Method , url: URL , accept: ContentType ? = . json, body: B , headers: [ String : String ] = [ : ] , expectedStatusCode: @escaping ( Int ) -> Bool = expected200to300, timeOutInterval : TimeInterval = 10 , query: [ String : String ] = [ : ] , encoder: JSONEncoder = JSONEncoder ( ) ) {
141
146
let b = try ! encoder. encode ( body)
142
- self . init ( method, url: url, accept: accept, contentType: . json, body: b, headers: headers, expectedStatusCode: expectedStatusCode, query: query, parse: { _, _ in . success( ( ) ) } )
147
+ self . init ( method, url: url, accept: accept, contentType: . json, body: b, headers: headers, expectedStatusCode: expectedStatusCode, timeOutInterval : timeOutInterval , query: query, parse: { _, _ in . success( ( ) ) } )
143
148
}
144
149
}
145
150
@@ -153,10 +158,11 @@ extension Endpoint where A: Decodable {
153
158
/// - accept: the content type for the `Accept` header
154
159
/// - headers: additional headers for the request
155
160
/// - expectedStatusCode: the status code that's expected. If this returns false for a given status code, parsing fails.
161
+ /// - timeOutInterval: the timeout interval for his request
156
162
/// - query: query parameters to append to the url
157
163
/// - decoder: the decoder that's used for decoding `A`s.
158
- public init ( json method: Method , url: URL , accept: ContentType = . json, headers: [ String : String ] = [ : ] , expectedStatusCode: @escaping ( Int ) -> Bool = expected200to300, query: [ String : String ] = [ : ] , decoder: JSONDecoder = JSONDecoder ( ) ) {
159
- self . init ( method, url: url, accept: accept, body: nil , headers: headers, expectedStatusCode: expectedStatusCode, query: query) { data, _ in
164
+ public init ( json method: Method , url: URL , accept: ContentType = . json, headers: [ String : String ] = [ : ] , expectedStatusCode: @escaping ( Int ) -> Bool = expected200to300, timeOutInterval : TimeInterval = 10 , query: [ String : String ] = [ : ] , decoder: JSONDecoder = JSONDecoder ( ) ) {
165
+ self . init ( method, url: url, accept: accept, body: nil , headers: headers, expectedStatusCode: expectedStatusCode, timeOutInterval : timeOutInterval , query: query) { data, _ in
160
166
return Result {
161
167
guard let dat = data else { throw NoDataError ( ) }
162
168
return try decoder. decode ( A . self, from: dat)
@@ -173,12 +179,13 @@ extension Endpoint where A: Decodable {
173
179
/// - body: the body of the request. This is encoded using a default encoder.
174
180
/// - headers: additional headers for the request
175
181
/// - expectedStatusCode: the status code that's expected. If this returns false for a given status code, parsing fails.
182
+ /// - timeOutInterval: the timeout interval for his request
176
183
/// - query: query parameters to append to the url
177
184
/// - decoder: the decoder that's used for decoding `A`s.
178
185
/// - encoder: the encoder that's used for encoding `A`s.
179
- public init < B: Encodable > ( json method: Method , url: URL , accept: ContentType = . json, body: B ? = nil , headers: [ String : String ] = [ : ] , expectedStatusCode: @escaping ( Int ) -> Bool = expected200to300, query: [ String : String ] = [ : ] , decoder: JSONDecoder = JSONDecoder ( ) , encoder: JSONEncoder = JSONEncoder ( ) ) {
186
+ public init < B: Encodable > ( json method: Method , url: URL , accept: ContentType = . json, body: B ? = nil , headers: [ String : String ] = [ : ] , expectedStatusCode: @escaping ( Int ) -> Bool = expected200to300, timeOutInterval : TimeInterval = 10 , query: [ String : String ] = [ : ] , decoder: JSONDecoder = JSONDecoder ( ) , encoder: JSONEncoder = JSONEncoder ( ) ) {
180
187
let b = body. map { try ! encoder. encode ( $0) }
181
- self . init ( method, url: url, accept: accept, contentType: . json, body: b, headers: headers, expectedStatusCode: expectedStatusCode, query: query) { data, _ in
188
+ self . init ( method, url: url, accept: accept, contentType: . json, body: b, headers: headers, expectedStatusCode: expectedStatusCode, timeOutInterval : timeOutInterval , query: query) { data, _ in
182
189
return Result {
183
190
guard let dat = data else { throw NoDataError ( ) }
184
191
return try decoder. decode ( A . self, from: dat)
0 commit comments