Remove urlEncodeParams for api route and always encode post params
This commit is contained in:
parent
45d9ad185c
commit
f25f2447a7
|
@ -3,9 +3,9 @@
|
|||
Until 1.0, breaking changes can occur in minor versions.
|
||||
|
||||
|
||||
## 0.6.1
|
||||
## 0.6.1 - 0.6.2
|
||||
|
||||
This version removes the explicit url encoding of `ApiRoute` query params, since the new query builder does this.
|
||||
These versions remove explicit url encoding of `ApiRoute` query params and always url encode form data params.
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -12,11 +12,6 @@ import Foundation
|
|||
This protocol represents an external api route, e.g. `login`
|
||||
or `user`. Each route is a separate action that defines all
|
||||
information required to perform an api request.
|
||||
|
||||
`IMPORTANT` Since the `postParams` and `queryParams` values
|
||||
are url encoded by `postParamsString` and `queryItems`, the
|
||||
resulting network call must not do this automatically. Just
|
||||
send them as is.
|
||||
*/
|
||||
public protocol ApiRoute {
|
||||
|
||||
|
@ -46,13 +41,6 @@ public protocol ApiRoute {
|
|||
performing a request.
|
||||
*/
|
||||
var queryParams: [String: String] { get }
|
||||
|
||||
/**
|
||||
Whether or not the route should url encode its post and
|
||||
query params. Return `false` if the params will contain
|
||||
chars that mustn't be url encoded, like array brackets.
|
||||
*/
|
||||
var urlEncodeParams: Bool { get }
|
||||
}
|
||||
|
||||
public extension ApiRoute {
|
||||
|
@ -72,7 +60,7 @@ public extension ApiRoute {
|
|||
var postParamsString: String? {
|
||||
var params = URLComponents()
|
||||
params.queryItems = postParams
|
||||
.map { URLQueryItem(name: $0.key, value: paramValue(for: $0.value)) }
|
||||
.map { URLQueryItem(name: $0.key, value: $0.value.urlEncoded()) }
|
||||
.sorted { $0.name < $1.name }
|
||||
return params.query
|
||||
}
|
||||
|
@ -128,10 +116,3 @@ public extension ApiRoute {
|
|||
environment.url.appendingPathComponent(path)
|
||||
}
|
||||
}
|
||||
|
||||
private extension ApiRoute {
|
||||
|
||||
func paramValue(for value: String) -> String? {
|
||||
urlEncodeParams ? value.urlEncoded() : value
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue