diff --git a/Spine/Query.swift b/Spine/Query.swift index 7b8fe89b..00d0e11c 100644 --- a/Spine/Query.swift +++ b/Spine/Query.swift @@ -41,6 +41,7 @@ public struct Query { public internal(set) var pagination: Pagination? + public internal(set) var customURLparams: [String: String] = [:] //MARK: Init @@ -274,6 +275,17 @@ public struct Query { 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 + } } diff --git a/Spine/Routing.swift b/Spine/Routing.swift index eb4b8851..3892b21e 100644 --- a/Spine/Routing.swift +++ b/Spine/Routing.swift @@ -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