URLEncodedFormEncoder
public final class URLEncodedFormEncoder
An object that encodes instances into URL-encoded query strings.
There is no published specification for how to encode collection types. By default, the convention of appending
[] to the key for array values (foo[]=1&foo[]=2), and appending the key surrounded by square brackets for
nested dictionary values (foo[bar]=baz) is used. Optionally, ArrayEncoding can be used to omit the
square brackets appended to array keys.
BoolEncoding can be used to configure how Bool values are encoded. The default behavior is to encode
true as 1 and false as 0.
SpaceEncoding can be used to configure how spaces are encoded. Modern encodings use percent replacement (%20),
while older encoding may expect spaces to be replaced with +.
This type is largely based on Vapor’s url-encoded-form project.
-
Configures how
See moreBoolparameters are encoded.Declaration
Swift
public enum BoolEncoding -
Configures how
See moreArrayparameters are encoded.Declaration
Swift
public enum ArrayEncoding -
Configures how spaces are encoded.
See moreDeclaration
Swift
public enum SpaceEncoding -
See moreURLEncodedFormEncodererror.Declaration
Swift
public enum Error : Swift.Error -
The
ArrayEncodingto use.Declaration
Swift
public let arrayEncoding: ArrayEncoding -
The
BoolEncodingto use.Declaration
Swift
public let boolEncoding: BoolEncoding -
The
SpaceEncodingto use.Declaration
Swift
public let spaceEncoding: SpaceEncoding -
The
CharacterSetof allowed characters.Declaration
Swift
public var allowedCharacters: CharacterSet -
Creates an instance from the supplied parameters.
Declaration
Swift
public init(arrayEncoding: ArrayEncoding = .brackets, boolEncoding: BoolEncoding = .numeric, spaceEncoding: SpaceEncoding = .percentEscaped, allowedCharacters: CharacterSet = .afURLQueryAllowed)Parameters
arrayEncodingThe
ArrayEncodinginstance. Defaults to.brackets.boolEncodingThe
BoolEncodinginstance. Defaults to.numeric.spaceEncodingThe
SpaceEncodinginstance. Defaults to.percentEscaped.allowedCharactersThe
CharacterSetof allowed (non-escaped) characters. Defaults to.afURLQueryAllowed. -
Encodes the
valueas a URL form encodedString.Declaration
Swift
public func encode(_ value: Encodable) throws -> StringParameters
valueThe
Encodablevalue.`Return Value
The encoded
String. -
Encodes the value as
Data. This is performed by first creating an encodedStringand then returning the.utf8data.Declaration
Swift
public func encode(_ value: Encodable) throws -> DataParameters
valueThe
Encodablevalue.Return Value
The encoded
Data.
View on GitHub
Install in Dash
URLEncodedFormEncoder Class Reference