Skip to content

Commit 544f712

Browse files
author
Jasper Blues
committed
Allow overridden parameter types on GET/DELETE
1 parent dde4d21 commit 544f712

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

2

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Allow overridden parameter types on GET/DELETE
2+
3+
# Please enter the commit message for your changes. Lines starting
4+
# with '#' will be ignored, and an empty message aborts the commit.
5+
#
6+
# Date: Fri Aug 6 10:54:16 2021 +0800
7+
#
8+
# On branch master
9+
# Your branch and 'origin/master' have diverged,
10+
# and have 1 and 1 different commits each, respectively.
11+
# (use "git pull" to merge the remote branch into yours)
12+
#
13+
# Changes to be committed:
14+
# modified: Sources/Networking+HTTPRequests.swift
15+
#
16+
# Untracked files:
17+
# .idea/
18+
#

Sources/Networking+HTTPRequests.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ public extension Networking {
1616
return handleJSONRequest(.get, path: path, cacheName: nil, parameterType: parameterType, parameters: parameters, responseType: .json, cachingLevel: cachingLevel, completion: completion)
1717
}
1818

19+
/// GET request to the specified path, allowing overridden parameter types
20+
///
21+
/// Overridden parameter types can be useful, for example some REST-ful APIs do not strictly adhere to spec.
22+
///
23+
/// - Parameters:
24+
/// - path: The path for the GET request.
25+
/// - parameterType: The parameters type to be used.
26+
/// - parameters: The parameters to be used, they will be serialized using Percent-encoding and appended to the URL.
27+
/// - completion: The result of the operation, it's an enum with two cases: success and failure.
28+
/// - Returns: The request identifier.
29+
@discardableResult
30+
func get(_ path: String, parameterType: ParameterType, parameters: Any? = nil, completion: @escaping (_ result: JSONResult) -> Void) -> String {
31+
handleJSONRequest(.get, path: path, cacheName: nil, parameterType: parameterType, parameters: parameters, responseType: .json, cachingLevel: .none, completion: completion)
32+
}
33+
1934
/// Registers a fake GET request for the specified path. After registering this, every GET request to the path, will return the registered response.
2035
///
2136
/// - Parameters:
@@ -205,6 +220,21 @@ public extension Networking {
205220
return handleJSONRequest(.delete, path: path, cacheName: nil, parameterType: parameterType, parameters: parameters, responseType: .json, cachingLevel: .none, completion: completion)
206221
}
207222

223+
/// DELETE request to the specified path, allowing overridden parameter types
224+
///
225+
/// Overridden parameter types can be useful, for example some REST-ful APIs do not strictly adhere to spec.
226+
///
227+
/// - Parameters:
228+
/// - path: The path for the DELETE request.
229+
/// - parameterType: The parameters type to be used.
230+
/// - parameters: The parameters to be used, they will be serialized using Percent-encoding and appended to the URL.
231+
/// - completion: The result of the operation, it's an enum with two cases: success and failure.
232+
/// - Returns: The request identifier.
233+
@discardableResult
234+
func delete(_ path: String, parameterType: ParameterType, parameters: Any? = nil, completion: @escaping (_ result: JSONResult) -> Void) -> String {
235+
handleJSONRequest(.delete, path: path, cacheName: nil, parameterType: parameterType, parameters: parameters, responseType: .json, cachingLevel: .none, completion: completion)
236+
}
237+
208238
/// Registers a fake DELETE request for the specified path. After registering this, every DELETE request to the path, will return the registered response.
209239
///
210240
/// - Parameters:

0 commit comments

Comments
 (0)