Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Spine/Query.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public struct Query<T: Resource> {

public internal(set) var pagination: Pagination?

public internal(set) var customURLparams: [String: String] = [:]

//MARK: Init

Expand Down Expand Up @@ -274,6 +275,17 @@ public struct Query<T: Resource> {
public mutating func paginate(_ pagination: Pagination?) {
self.pagination = pagination
}


// MARK: Custom URL params

/// Add custom URL parameter. Pass value=nil to remove parameter.
///
/// - parameter key: key of added parameter
/// - parameter value: value of added parameter (URL...&key=value&...)
public mutating func addCustomURLparameter(_ key: String, value: String?) {
self.customURLparams[key] = value
}
}


Expand Down
7 changes: 7 additions & 0 deletions Spine/Routing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ open class JSONAPIRouter: Router {
}
}

// Custom URL params
for itemKey in query.customURLparams.keys {
let value = query.customURLparams[itemKey]
let item = URLQueryItem(name: itemKey, value: value)
appendQueryItem(item, to: &queryItems)
}

// Compose URL
if !queryItems.isEmpty {
urlComponents.queryItems = queryItems
Expand Down