Encoder & decoder for working with Codable types as URLQueryItems.
About
URLQueryItemCoder provides an implementation of Swift’s Encoder protocol suitable for encoding an Encodable type as
an array of URLQueryItems, and an implementation of Swift’s Decoder protocol suitable for decoding a Decodable
type from an array of URLQueryItems.
This allows us to lift URLQueryItem requirements into the type system (e.g. modeling an HTTP GET API).
Capabilities
URLQueryItemCoder is an exhaustive implementation with an exhaustive test suite.
Standard
All standard features expected by the protocols are supported.
Single-value containers
Keyed containers
Unkeyed containers
Nested containers
Inheritance
Extra
All extra features offered by Swift’s JSON implementations are supported.
Data special treatment
Date special treatment
Double & Float special treatment
Key conversions
Sorted keys
Usage
Encoding
URLQueryItemEncoder can be configured through its initializer or strategies and outputFormatting properties.
For example, given…
import URLQueryItemCoder
struct Interval: Codable {
let start: Date
let end: Date
}
struct GetPostsQuery: Codable {
let interval: Interval
let userID: String
}
let interval = Interval(start: .now.addingTimeInterval(-1_000), end: .now)
let query = GetPostsQuery(interval: interval, userID: "123abc")
URLQueryItemCoder
Encoder & decoder for working with
Codabletypes asURLQueryItems.About
URLQueryItemCoder provides an implementation of Swift’s
Encoderprotocol suitable for encoding anEncodabletype as an array ofURLQueryItems, and an implementation of Swift’sDecoderprotocol suitable for decoding aDecodabletype from an array ofURLQueryItems.This allows us to lift
URLQueryItemrequirements into the type system (e.g. modeling anHTTP GETAPI).Capabilities
URLQueryItemCoder is an exhaustive implementation with an exhaustive test suite.
Standard
All standard features expected by the protocols are supported.
Extra
All extra features offered by Swift’s JSON implementations are supported.
Dataspecial treatmentDatespecial treatmentDouble&Floatspecial treatmentUsage
Encoding
URLQueryItemEncodercan be configured through its initializer orstrategiesandoutputFormattingproperties.For example, given…
Then…
Decoding
URLQueryItemDecodercan be configured through its initializer orstrategyproperty.For example, given…
Then…
Supported Platforms
Requirements
Installation
Swift Package Manager
Documentation
Documentation is available on GitHub Pages.
Contributions
URLQueryItemCoder is not accepting source contributions at this time. Bug reports will be considered.
Author
Kyle Hughes
License
URLQueryItemCoder is available under the MIT license.
See
LICENSEfor details.