Skip to content

Commit

Permalink
Merge pull request #63 from futuredapp/feature/url-query-as-KeyValueP…
Browse files Browse the repository at this point in the history
…airs

Use KeyValuePairs instead of Dictionary for url query
  • Loading branch information
mkj-is authored Jan 26, 2021
2 parents 69baa18 + 084abcb commit f8c9f6f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Sources/FTAPIKit/Endpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public protocol Endpoint {

var headers: [String: String] { get }

var query: [String: String] { get }
var query: KeyValuePairs<String, String> { get }

/// HTTP method/verb describing the action.
var method: HTTPMethod { get }
}

public extension Endpoint {
var headers: [String: String] { [:] }
var query: [String: String] { [:] }
var query: KeyValuePairs<String, String> { [:] }
var method: HTTPMethod { .get }
}

Expand All @@ -42,7 +42,7 @@ public protocol MultipartEndpoint: Endpoint {
}

public protocol URLEncodedEndpoint: Endpoint {
var body: [String: String] { get }
var body: KeyValuePairs<String, String> { get }
}

/// Endpoint protocol extending `Endpoint` having decodable associated type, which is used
Expand Down
2 changes: 1 addition & 1 deletion Sources/FTAPIKit/URLRequestBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct URLRequestBuilder<S: URLServer> {
}
}

private func queryItems(parameters: [String: String]) -> [URLQueryItem] {
private func queryItems(parameters: KeyValuePairs<String, String>) -> [URLQueryItem] {
parameters.compactMap { key, value in
guard let encodedKey = key.addingPercentEncoding(withAllowedCharacters: .urlQueryNameValueAllowed),
let encodedValue = value.addingPercentEncoding(withAllowedCharacters: .urlQueryNameValueAllowed) else {
Expand Down
2 changes: 1 addition & 1 deletion Tests/FTAPIKitTests/Mockups/Endpoints.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct TestMultipartEndpoint: MultipartEndpoint {
struct TestURLEncodedEndpoint: URLEncodedEndpoint {
let path = "post"
let method: HTTPMethod = .post
let body: [String: String] = [
let body: KeyValuePairs<String, String> = [
"param1": "value1",
"param2": "value2"
]
Expand Down

0 comments on commit f8c9f6f

Please sign in to comment.