Query
Parsing
Serde.SerdeQuery.parse_query — Function
parse_query(x::Union{AbstractString, Vector{UInt8}}; dict_type = Dict{String,Any}, delimiter = "&") -> DictParse a URL-encoded query string into a Dict without mapping to a target type.
Keys and values are percent-decoded. Repeated keys (e.g. a=1&a=2) produce a Vector of values.
Arguments
x: query string asStringorVector{UInt8}(leading?should be stripped).
Keyword arguments
dict_type::Type{<:AbstractDict}: concrete dict type (defaultDict{String,Any}).delimiter::AbstractString = "&": pair separator.
Returns
A dict mapping decoded keys to decoded values (or vectors of values).
Throws
ParseError: if the query string contains invalid percent-encoding or semicolons.
Examples
julia> parse_query("name=Alice&age=30")
Dict{String, Any}("name" => "Alice", "age" => "30")
julia> parse_query("color=red&color=blue")
Dict{String, Any}("color" => ["red", "blue"])See also: from_query, try_from_query.
Deserialization
Serde.SerdeQuery.from_query — Function
from_query(::Type{T}, x; kw...) -> T
from_query(strategy, ::Type{T}, x; kw...) -> T
from_query(f::Function, x; kw...) -> AnyParse a URL query string and deserialize it into type T.
All values in a query string are strings; the deserialization engine handles type coercion for each field. Vector/Set fields are populated from repeated keys or bracket notation.
Pass a strategy object (e.g. CamelCase()) to apply global field-renaming.
Arguments
::Type{T}: target type to construct.x: query string asStringorVector{UInt8}.strategy: optional serialization strategy.
Returns
A value of type T.
Throws
ParseError: ifxcontains invalid percent-encoding.MissingFieldError: if a required struct field is absent.TypeMismatchError: if a value cannot be coerced to the field type.
Examples
julia> struct Filter; name::String; limit::Int; end
julia> from_query(Filter, "name=Alice&limit=10")
Filter("Alice", 10)See also: try_from_query, to_query, parse_query.
Serde.SerdeQuery.try_from_query — Function
try_from_query(::Type{T}, x; kw...) -> Union{T, SerdeError}
try_from_query(strategy, ::Type{T}, x; kw...) -> Union{T, SerdeError}Like from_query but returns a SerdeError instead of throwing on failure.
Returns
Ton success.- A
ParseErrororDeserErrorsubtype on failure.
See also: from_query, SerdeError.
Serialization
Serde.SerdeQuery.to_query — Function
to_query(data; delimiter = "&", sort_keys = false, escape = true) -> String
to_query(strategy, data; delimiter = "&", sort_keys = false, escape = true) -> StringSerialize data into a URL-encoded query string.
Struct fields and dict keys become query parameter names; values are converted to strings. Vector and Set values are serialized in bracket notation ([v1,v2]). Null values (nothing, missing) and skipped fields are omitted.
Pass a strategy object (e.g. CamelCase()) to apply global field-renaming.
All serialization traits (Serde.ser_name, Serde.ser_value, Serde.ser_skip) are applied.
Arguments
data: value to serialize (struct or dict).strategy: optional serialization strategy.
Keyword arguments
delimiter::AbstractString = "&": separator betweenkey=valuepairs.sort_keys::Bool = false: sort parameter names lexicographically before output.escape::Bool = true: percent-encode characters outside the unreserved set.
Returns
A query string String (without a leading ?).
Examples
julia> struct Search; query::String; limit::Int; end
julia> to_query(Search("hello world", 10))
"query=hello%20world&limit=10"
julia> to_query(Search("hello world", 10); escape=false)
"query=hello world&limit=10"
julia> to_query(Search("hello", 10); sort_keys=true)
"limit=10&query=hello"See also: from_query.