Skip to content

Commit

Permalink
Allow overridden parameter types on GET/DELETE
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasper Blues committed Aug 6, 2021
1 parent dde4d21 commit cdee18c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Sources/Networking+HTTPRequests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ public extension Networking {
return handleJSONRequest(.get, path: path, cacheName: nil, parameterType: parameterType, parameters: parameters, responseType: .json, cachingLevel: cachingLevel, completion: completion)
}

/// GET request to the specified path, allowing overridden parameter types
///
/// Overridden parameter types can be useful, for example some REST-ful APIs do not strictly adhere to spec.
///
/// - Parameters:
/// - path: The path for the GET request.
/// - parameterType: The parameters type to be used, by default is none.
/// - parameters: The parameters to be used, they will be serialized using Percent-encoding and appended to the URL.
/// - completion: The result of the operation, it's an enum with two cases: success and failure.
/// - Returns: The request identifier.
@discardableResult
func get(_ path: String, parameterType: ParameterType = .none, parameters: Any? = nil, completion: @escaping (_ result: JSONResult) -> Void) -> String {
handleJSONRequest(.get, path: path, cacheName: nil, parameterType: parameterType, parameters: parameters, responseType: .json, cachingLevel: .none, completion: completion)
}

/// Registers a fake GET request for the specified path. After registering this, every GET request to the path, will return the registered response.
///
/// - Parameters:
Expand Down Expand Up @@ -205,6 +220,21 @@ public extension Networking {
return handleJSONRequest(.delete, path: path, cacheName: nil, parameterType: parameterType, parameters: parameters, responseType: .json, cachingLevel: .none, completion: completion)
}

/// DELETE request to the specified path, allowing overridden parameter types
///
/// Overridden parameter types can be useful, for example some REST-ful APIs do not strictly adhere to spec.
///
/// - Parameters:
/// - path: The path for the DELETE request.
/// - parameterType: The parameters type to be used, by default is none.
/// - parameters: The parameters to be used, they will be serialized using Percent-encoding and appended to the URL.
/// - completion: The result of the operation, it's an enum with two cases: success and failure.
/// - Returns: The request identifier.
@discardableResult
func delete(_ path: String, parameterType: ParameterType = .none, parameters: Any? = nil, completion: @escaping (_ result: JSONResult) -> Void) -> String {
handleJSONRequest(.delete, path: path, cacheName: nil, parameterType: parameterType, parameters: parameters, responseType: .json, cachingLevel: .none, completion: completion)
}

/// Registers a fake DELETE request for the specified path. After registering this, every DELETE request to the path, will return the registered response.
///
/// - Parameters:
Expand Down

0 comments on commit cdee18c

Please sign in to comment.